Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot provide custom 500 error messages #9

Open
nicolasgarnil opened this issue Feb 27, 2017 · 0 comments
Open

Cannot provide custom 500 error messages #9

nicolasgarnil opened this issue Feb 27, 2017 · 0 comments

Comments

@nicolasgarnil
Copy link

nicolasgarnil commented Feb 27, 2017

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 nicolasgarnil changed the title Provide generic error messages instead of exception messages Cannot provide custom error messages 500 error messages Mar 2, 2017
@nicolasgarnil nicolasgarnil changed the title Cannot provide custom error messages 500 error messages Cannot provide custom 500 error messages Mar 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant