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

Middleware loggers unaware about rescue_from handlers #1734

Closed
thedarkside opened this issue Jan 29, 2018 · 5 comments
Closed

Middleware loggers unaware about rescue_from handlers #1734

thedarkside opened this issue Jan 29, 2018 · 5 comments
Labels

Comments

@thedarkside
Copy link

As far as i digged in the code it seems that loggers realized as middleware are not aware of changes to exceptions made by rescue_from handlers.

I stumbled upon this as i saw log entries with a wrong statuscode in my application. I am catching an UnauthorizedException in a rescue_from block and setting the desired statuscode with error! e, 401. It works as expected but produces a 500 log entry.

Maybe worth a discussion about possible solutions?

@dblock
Copy link
Member

dblock commented Jan 29, 2018

Care to provide a more detailed example with some code maybe?

@thedarkside
Copy link
Author

thedarkside commented Jan 29, 2018

@dblock thank you for listening but i think i figured it out myself. I've inserted now the logger before Grape::Middleware::Error which handles the rescue_from blocks and then passes the exception with the right status code to the logger. see: aserafin/grape_logging#45 (comment)

It was tricky to figure out the actual middleware stack. I just saw it in a stacktrace while debugging. It would be nice to have a convinient rake task which prints out the whole middleware stack just like in rails + some more detailed documentation about it.

@dblock
Copy link
Member

dblock commented Jan 29, 2018

Maybe you can contribute something? At least some documentation as well as details of how you solved this here. You can then close the issue?

@thedarkside
Copy link
Author

The solution is already linked.
For loggers in general insert them like this insert_before Grape::Middleware::Error,... or insert_after Rack::Head,... instead of use ...
Maybe document it explicit in your readme?

@dblock
Copy link
Member

dblock commented Jan 30, 2018

Yes, please PR a change to README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants