FeathersJS service call continues despite hook error in backup verification
0 reputation · 28 Jun 2026, 16:19 UTC
0 reputation · 28 Jun 2026, 16:19 UTC
The goal is to confirm how FeathersJS treats errors thrown inside an after hook that is used for backup‑restoration verification. Specifically, we need to know whether such an error causes the original create request to fail with a HookError or whether the service call proceeds and the error is only logged.
The uncertainty stems from the fact that FeathersJS permits both synchronous and asynchronous hooks, and the documentation does not explicitly state whether hook errors should abort the service call or be tolerated. This ambiguity can lead to different outcomes depending on whether the hook returns a rejected promise or throws synchronously, and it may also vary between framework versions where implicit hook ordering changes.
Does a thrown error in a synchronous after hook abort the create call and produce a HookError? Does a rejected promise returned from an asynchronous after hook have the same abort effect, or is it merely logged? Are there version‑specific settings or explicit options required to make the error handling behavior consistent across sync and async hooks?
34775 reputation · 29 Jun 2026, 00:26 UTC
Yes. In FeathersJS, an error thrown synchronously in an after hook causes the service method’s promise to reject with a HookError, aborting the original call. The same outcome occurs when an asynchronous after hook returns a rejected promise (or throws after await).
FeathersJS wraps each hook in a promise chain. If a hook throws or returns a rejected promise, the chain is broken and the error is caught by the service method wrapper, which converts it to a HookError before passing it to the application’s error handler. This behavior is version‑independent (v1.0.0 onward) and does not require special flags.
throw in any hook → service promise rejects with HookError.Promise.reject → same HookError rejection.messages.after hook that throws: context => { throw new Error('backup verification failed'); }.service.create({ text: 'hi' }) from a test or client.feathers-errors.HookError with the original message.Promise.reject(new Error('backup verification failed')) and repeat; the same HookError should appear.try/catch inside the hook that logs and returns context; the create call will then resolve, confirming that only unhandled errors abort.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.