Skip to content
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
merged 1 commit into from
Sep 27, 2017

Conversation

JaneOri
Copy link
Contributor

@JaneOri JaneOri commented Sep 27, 2017

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 be null. The original result can still be accessed from hook.original.result.

@daffl daffl merged commit f9b41f3 into feathersjs-ecosystem:master Sep 27, 2017
@daffl
Copy link
Member

daffl commented Sep 27, 2017

Thank you James. Released as 2.1.0

@marshallswain
Copy link
Member

Thanks @daffl

@FossPrime
Copy link

Seems like setting hook.result in a find is not good enough to pass the hook validation step... ideas? get error hooks work great however.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants