Move the inclusion of mixin to the bottom of the controller for customizable error handling #148
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, thank you very much for awesome gem.
I'm developing SCIM feature with your gem in my company.
Suggestion
I would like you to move the inclusion of
application_controller_mixin
to the bottom of the controller to allow to override the error handler methods or some other methods.Or I would like you to create a new option to customize error handling.
This PR is for 1st suggestion.
Background
If the inclusion of
application_controller_mixin
is before the method definitions, the methods defined in mixin are overridden by the methods originally defined inScimitar::ApplicationController
.scimitar/app/controllers/scimitar/application_controller.rb
Lines 12 to 14 in 9b4899c
This prevents overriding the controller's method with the mixin. This may be intentional.
In fact, we cannot override instance method itself, but we can override
rescue_from
like the following.(Assume that we want to change the behavior of
handle_unexpected_error
(error handling forStandardError
).)However, it changes the priority of
rescue_from
like the following.As a result, all errors, including
ActionDispatch::Http::Parameters::ParseError
andScimitar::ErrorResponse
, will be handled by thecustom_unexpected_error_handler
.If we want to avoid this, we will need to enumerate all originally defined
rescue_from
like below.However, this is unhealthy.
If the original definitions of
Scimitar::ApplicationController
change, we must follow them.I believe allowing to override the controller methods is better for any cases.
My Final Goal
Ultimately, I want to add the error reporting and customize the error message for 500 errors like the following.
I want to hide the concrete error message to prevent the internal matter is exposed to out customer.