Skip to content

Exceptions thrown in the formatter should be catchable by rescue_from :all #359

Closed
@lucaspiller

Description

@lucaspiller

I added a basic error handler using rescue_from :all that logs exceptions, notifies Airbrake and returns a basic 500 response. Unfortunately this doesn't work as described in the documentation, and this isn't called for all exceptions.

We had an issue with a decorator not being found, and so the formatter (we are using Rabl) was throwing an exception. This was caught here, and thrown again:

lib/grape/middleware/formatter.rb

This was caught in the error middleware and passed directly to error_response with no options for logging or changing it (other than by hacking around with error_formatter):

lib/grape/middleware/error.rb

In the end I changed the error middleware to raise an exception for this exception (...) which isn't great, but it allows me to return consistent errors when something goes wrong. It would be great if rescue_from :all worked as described, and allowed you to rescue from all exceptions 😄

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions