Allow ctrl.before to prevent further processing of the request #1023
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.
A useful (but apparently unintended) use of
ctrl.before
is to impose access restrictions.Currently the only way to prevent further processing of a request in
ctrl.before
is to throw an exception. But this yields a route handling error, which results in a stacktrace returned as plaintext response. This is less than ideal.This change allows
ctrl.before
callbacks to explicitly returnfalse
to prevent any further processing of the request. As the response body can be accessed inctrl.before
callbacks already, this also provides a workaround for use cases requiring intercepting all supported HTTP verbs in a single function.Returning
false
to prevent further processing should be familiar to many JS devs from client-side event handling and libraries likeunderscore
.@moonglum, @fceller does this make any sense to you?