-
Notifications
You must be signed in to change notification settings - Fork 117
bundled hooks customize errors #215
Comments
I've been thinking of adding const errors = require('feathers-errors');
app.service('messages').afterError({
create(hook) {
const originalError = hook.error;
hook.error = errors.Conflict(originalError.message);
}
}); Would that solve your problem as well? |
@daffl but for now. this is no way to do this. I will wait.
or
|
@colinshen I like that second syntax option. I think we definitely need something more like an |
If we are considering customizing the error messages we should support it everywhere (e.g. the database adapters etc.). |
@daffl totally. Which is why I want to be lazy and not do that. 😝 In seriousness, I do think so. It is a lot of work but we need something to better handle errors in the hooks chain. Ideally I want something like the express error middleware, where you can chain together multiple error handling hooks to build up the error output you want. So, if you wanted custom error messages you would check for the status code and modify as necessary. |
So we had a revelation the other day. If you need custom conditions or custom errors you can simply wrap the hook in your own hook like so: import { hooks } from 'feathers-authentication';
exports.hashPassword = function(options) {
// Add any custom options
function(hook) {
return new Promise((resolve, reject) => {
if (myCondition !== true) {
return resolve(hook);
}
// call the original hook
hooks.hashPassword(options)(hook)
.then(hook => {
// do something custom
resolve(hook);
})
.catch(error => {
// do any custom error handling
error.message = 'my custom message';
reject(error);
});
});
});
} Going to close this as this is the best solution. It's the most flexible and doesn't require any change to existing hooks. |
I can't find a way to do this in docs unless using my own middlewares.
The text was updated successfully, but these errors were encountered: