Comments (5)
One way this is already possible would be to .catch
the promise and return a normal value instead of throwing another error. So in the hook you could add a result
property to the error
object, then check for it in the catch
and return it like so:
app.service('myservice').create().catch(error => {
if(error.result) {
return error.result;
}
throw error;
});
I think it wouldn't be very hard to add as a feature either. Basically we just have to change https://github.com/feathersjs/feathers-hooks/blob/master/src/hooks.js#L105 to
.then(hook => {
if(hook.error) {
return Promise.reject(hook.error);
}
return hook.result;
});
from feathers-hooks.
This will be available in the next version of Feathers core which will include feathers-hooks
.
Closed via feathersjs/feathers#621
from feathers-hooks.
Or like in before
hooks: if in error
hook the hook.result
is set, then the error is swallowed, and the hook.result
is returned as if the service method succeeds as normal.
from feathers-hooks.
@daffl Yes in old days without error
hooks, I was using .catch
to do this. However, .catch
has to be written after the method calling code (as your example shows), and it is way better to hide this kind of logic into error
hooks so the users of the service just call app.service('xxx')
and no need to care about the .catch
thing.
from feathers-hooks.
nice~!
from feathers-hooks.
Related Issues (20)
- Composing Hooks HOT 4
- Population fails on empty values HOT 1
- Calling populate(target, options) is now DEPRECATED HOT 3
- V1.7.1: Module not found: Error: Can't resolve 'feathers-hooks-common/lib/populate' in '/app/node_modules/feathers-hooks/lib' @ ./~/feathers-hooks/lib/hooks.js 13:16-61 HOT 7
- how to get service name(path) in hook functions? HOT 2
- Gravatar example doesn't work?! HOT 15
- Test Hooks HOT 8
- feathers-hooks-common/lib/populate, feathers-hooks-common/lib/bundled not found. HOT 7
- An in-range update of mongoose is breaking the build 🚨
- `__hooks` of existing service should not be overwritten HOT 4
- __hooks being overwritten HOT 3
- Add hook to the top of others hook HOT 5
- [discussion] maybe change the name of the context parameter from 'hook' to 'context' or use 'this' in the future? HOT 10
- Params are not populated when called internally HOT 1
- Error: 'chck' is not a valid hook method HOT 1
- Hook typings HOT 3
- Angular 4 feathers hook build fails - "All declarations of 'Service' must have identical type parameters" HOT 3
- Populate hook with array of one ref return object not an array. HOT 1
- Call others service then, dissallow original service
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from feathers-hooks.