8000 Allow methods to return a null result by bertho-zero · Pull Request #865 · feathersjs/feathers · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lib/hooks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { hooks, validateArguments, isPromise } = require('@feathersjs/commons');
const { hooks, validateArguments, isPromise, _ } = require('@feathersjs/commons');

const {
createHookObject,
Expand Down Expand Up @@ -98,12 +98,11 @@ const hookMixin = exports.hookMixin = function hookMixin (service) {
const hookChain = errorHooks.concat(finallyHooks);

// A shallow copy of the hook object
const errorHookObject = Object.assign({}, error.hook, hookObject, {
const errorHookObject = _.omit(Object.assign({}, error.hook, hookObject, {
type: 'error',
result: null,
original: error.hook,
error
});
}), 'result');

return processHooks.call(service, hookChain, errorHookObject)
.catch(error => {
Expand All @@ -114,12 +113,12 @@ const hookMixin = exports.hookMixin = function hookMixin (service) {
.then(hook => {
if (returnHook) {
// Either resolve or reject with the hook object
return hook.result ? hook : Promise.reject(hook);
return typeof hook.result !== 'undefined' ? hook : Promise.reject(hook);
}

// Otherwise return either the result if set (to swallow errors)
// Or reject with the hook error
return hook.result ? hook.result : Promise.reject(hook.error);
return typeof hook.result !== 'undefined' ? hook.result : Promise.reject(hook.error);
});
});
};
Expand Down
Loading
0