-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Grape exception handling #1756
Grape exception handling #1756
Conversation
CHANGELOG.md
Outdated
@@ -13,6 +13,7 @@ | |||
* [#1750](https://github.com/ruby-grape/grape/pull/1750): Fix a circular dependency warning due to router being loaded by API - [@salasrod](https://github.com/salasrod). | |||
* [#1752](https://github.com/ruby-grape/grape/pull/1752): Fix `include_missing` behavior for aliased parameters - [@jonasoberschweiber](https://github.com/jonasoberschweiber). | |||
* [#1754](https://github.com/ruby-grape/grape/pull/1754): Allow rescue from non-`StandardError` exceptions to use default error handling - [@jelkster](https://github.com/jelkster). | |||
* [#1756](https://github.com/ruby-grape/grape/pull/1756): Allow custom Grape exception handlers when the build-in exception handling is enabled - [@soylent](https://github.com/soylent). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: builT-in
lib/grape/middleware/error.rb
Outdated
@@ -122,16 +85,51 @@ def format_message(message, backtrace, original_exception = nil) | |||
|
|||
private | |||
|
|||
def rescue_all? | |||
options[:rescue_all] | |||
DEFAULT_RESCUE_HANDLER = :handle_error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems pretty but maybe unnecessary? I mean :handle_error
is already a constant, since this isn't going to change I say copy-paste it everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... or maybe even rename it to :default_rescue_handler
?
Perfect, thanks. See minor comments above. |
Allow custom Grape exception handlers when the built-in exception handling is enabled
@dblock All done |
Merged, thanks. |
This pull request fixes Grape exception handling for the following case:
I reworked
Grape::Middleware::Error
a bit:options[:rescue_handlers]
andoptions[:base_only_rescue_handlers]
only onceoptions[:base_only_rescue_handlers]
should have higher priority thanoptions[:rescue_handlers]
because it is more restrictive