This repository has been archived by the owner on Apr 20, 2018. It is now read-only.
Allow errors to be swallowed in error hooks #170
Merged
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.
For #151
This is (mostly) just copying the necessary parts and test from @daffl's fix found in the main project:
https://github.com/feathersjs/feathers/pull/621/files
Use case:
I have a create user (sign up) service that returns just the email that was entered and we show a message that says something like
Email sent! Please check ${response.email} for additional information.
However, if the user already exists then the service returns an error - which is good if the server or an admin user runs it.
BUT if the request is from a non-admin end user, we need to return the original non-error reply as if the email didn't exist. (so we don't leak information to anyone maliciously using the form about who's registered)
In order to do that in a clean way, we need to conditionally swallow the error in an error hook.
Breaking change:
If
hook.result
is set and then an error happens,hook.result
will now benull
. The original result can still be accessed fromhook.original.result
.