Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

onError hooks functionality #109

Merged
merged 4 commits into from
Oct 14, 2016
Merged

onError hooks functionality #109

merged 4 commits into from
Oct 14, 2016

Conversation

daffl
Copy link
Member

@daffl daffl commented Oct 12, 2016

This allows to register onError hooks the same way as before and after hooks:

const app = feathers().configure(hooks()).use('/dummy', {
  get() {
    return Promise.reject(new Error('Something went wrong'));
  }
});
const service = app.service('dummy');

service.onError(function(hook) {
  // hook.type === 'onError'
  // hook.error === Error('Something went wrong')
  throw new Error('This is another error');
});

service.get().catch(e => console.error(e));

Closes #83

@ekryski
Copy link
Member

ekryski commented Oct 12, 2016

Awesome @daffl! Being super knit-picky but do you want to just call it error instead of onError so that it looks similar to before and after? I think service.error is nice.

Totes your call. Other than that :shipit:. Stoked for this to land!

@marshallswain
Copy link
Member

Since before, on, and after are all prepositions and convey location, I prefer it to be onError. My 2 bits.

@eddyystop
Copy link
Contributor

Would we want to know where the error occurred: before hooks, operation itself, after hooks? Perhaps that depends on whether the DB remains updated if its the after hooks that throw.

@daffl
Copy link
Member Author

daffl commented Oct 13, 2016

I thought about that but realized that you can get the original hook via hook.error.hook. Maybe we should alias it to hook.source?

@eddyystop
Copy link
Contributor

Something like errorSource may be more self-explanatory?

@ekryski
Copy link
Member

ekryski commented Oct 13, 2016

I agree with @eddyystop unless it simply becomes hook.error.source.

I noticed that we probably want to add a test to ensure you can chain up multiple error hooks (I think that's what we had intended).

@daffl daffl merged commit d177fc3 into master Oct 14, 2016
@daffl daffl deleted the onerror-hooks branch October 14, 2016 06:37
@daffl daffl removed the in progress label Oct 14, 2016
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