Added support for router specific error handler #328
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.
Related open issues: #308
I have added support for router-specific error handlers, with a view to support router-specific not found handlers if this PR is successful. Slight changes have also been made to the docs to reflect the new feature. All current branch tests pass so I don't believe there are any breaking changes in this request.
I do note though that in thethrow
method onResponse
because the error handlers were not originally called in areturn
statement the control is still passed to middleware and in some instances breaks the expected behaviour of the error handler itself. For this reason I have also made a change to this method to preserve the expected behaviour of the error handler.If this is a PR that will be accepted I do plan to add tests using
supertest
andjest
(purely to simplify the testing for myself) to ensure the error handlers behave as expected. As mentioned above, I believe there is a natural progression here to add support for router-specific not found handlers and again if this PR is accepted I will look to continue in this direction. A small demo can be found hereEDIT: The earlier encountered problem with the
Response.throw
method was an artifact of my tsconfig in the demo. I have reverted this change and updated the demo repo.