restfulness icon indicating copy to clipboard operation
restfulness copied to clipboard

Cannot provide custom 500 error messages

Open nicolasgarnil opened this issue 8 years ago • 0 comments

Problem

It would be desirable to be able to provide generic error messages instead of the exception message after a resource method raises a StandardError.

Proposed solution

We can include ActiveSupport::Rescuable in Restfulness::Resource (active_support is already a dependency of restfulness) to allow resources to declare custom error handlers via rescue_from.

Something like:

class ApplicationResource < Restfulness::Resource  
  rescue_from StandardError do
    self.status, self.payload = [500, { message: 'Internal Server Error' }]
  end
end

And then, in the Restfulness::Response object ask if the resource has error handlers for that type of error before rendering the default error message (e.message).

Any thoughts?

nicolasgarnil avatar Feb 27 '17 14:02 nicolasgarnil