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

Ignore a Controller or specific endpoint? #472

Open
dhempy opened this issue Aug 27, 2020 · 4 comments
Open

Ignore a Controller or specific endpoint? #472

dhempy opened this issue Aug 27, 2020 · 4 comments

Comments

@dhempy
Copy link

dhempy commented Aug 27, 2020

I'd like for better_errors to not do anything for a given endpoint or controller.

For example, I have UptimeController#example_error that intentionally raises an error to aid in system monitoring. This works fine in prod, but in dev better_errors does its job and returns a better error message.

But I don't want it to. I want to actually see the error returned to the browser, as it will in prod.

I've tried:
BetterErrors.ignored_classes = ['ActionDispatch::Request', 'ActionDispatch::Response', 'UptimeController']

...but I guess that only affects inspection, not rescuing.

Is it currently possible to suppress better_errors for one endpoint?

If not, would this be useful to others? I don't mind taking it on, if the community doesn't think it's a dumb idea.

@RobinDaugherty
Copy link
Member

RobinDaugherty commented Sep 17, 2020

@dhempy it does seem useful to provide a list of exception classes that should not be caught by Better Errors. Something like ignored_exception_classnames? (I would like to rename ignored_classes to be more meaningful.)

I suppose it also could be possible to do the same thing with path matching, but I think exception classnames would be more broadly useful.

@k1w1
Copy link

k1w1 commented Jan 24, 2021

I have the same requirement. I would like to disable better_errors for all requests to our API controllers, but have better_errors work for non-API controllers. In development I still want the API controller to return the same error response it would in production so I can do development on the error handling of API clients.

@RobinDaugherty
Copy link
Member

@k1w1 Better Errors will only change the response for an unhandled exception. If you want development to act the same as production, it would be best to add a rescue_from handler to your controller. This is good practice anyway so you can report/log your exception and control the response.

Now that I've read your comment, I realize this might be the answer that @dhempy might be looking for.

@k1w1
Copy link

k1w1 commented Feb 2, 2021

Thanks, that makes perfect sense now. I just need to rescue_from all errors to control the response.

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

3 participants