-
-
Notifications
You must be signed in to change notification settings - Fork 190
Add ability to add handlers for raised exceptions #688
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
Conversation
src/kemal/exception_handler.cr
Outdated
@@ -11,12 +11,26 @@ module Kemal | |||
rescue ex : Kemal::Exceptions::CustomException | |||
call_exception_with_status_code(context, ex, context.response.status_code) | |||
rescue ex : Exception | |||
# Use error handler defined for the current exception if it exists | |||
return call_exception_with_exception(context, ex, 500) if Kemal.config.error_handlers.has_key?(ex.class) |
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.
This line is added above the log
function in order for the specs to pass.
A logger is needed for #log
to be able to successfully run which the tests in exception_handler_spec.cr
doesn't appear to have defined.
This shouldn't be a problem in the real world case as a logger would always exist afaik.
Please let me know if this should be rectified in some other way.
This is perfect! |
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
e7f441a
to
bf19e27
Compare
`ex.class <= key` below should already handle the exact match ```crystal Kemal.config.error_handlers.each_key do |key| if ex.class <= key end end ```
Prior to this commit, handlers for exceptions and handlers for HTTP status codes were stored in a single collection. However, the two are used completely independently from each other and should instead be stored in two separate collections.
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.
LGTM @syeopite, thanks a lot 👍 Waiting for the review of @straight-shoota ⌛
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.
Thanks a lot @syeopite 👍
Kilt is unmaintained and the ECR templating logic has been natively integrated into Kemal with the issues previously seen having been resolved. This commit is mostly a precursor to support the next Kemal release which will add the ability to create error handlers for raised exceptions. See kemalcr/kemal#688
Kilt is unmaintained and the ECR templating logic has been natively integrated into Kemal with the issues previously seen having been resolved. This commit is mostly a precursor to support the next Kemal release which will add the ability to create error handlers for raised exceptions. See kemalcr/kemal#688
Kilt is unmaintained and the ECR templating logic has been natively integrated into Kemal with the issues previously seen having been resolved. This commit is mostly a precursor to support the next Kemal release which will add the ability to create error handlers for raised exceptions. See kemalcr/kemal#688
Closes #622
Description of the Change
This PR adds the ability for users to define error handlers that are used when a specific exception is raised.
Alternate Designs
Benefits
This provides for a cleaner and easier experience for defining custom errors. See #622.
Possible Drawbacks