mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
fix(core): Return original hooks errors to the frontend (#13365)
This commit is contained in:
parent
966d60a39a
commit
5439181e92
|
@ -106,13 +106,12 @@ describe('ExternalHooks', () => {
|
|||
});
|
||||
|
||||
it('should report error if hook execution fails', async () => {
|
||||
hookFn.mockRejectedValueOnce(new Error('Hook failed'));
|
||||
const error = new Error('Hook failed');
|
||||
hookFn.mockRejectedValueOnce(error);
|
||||
// eslint-disable-next-line @typescript-eslint/dot-notation
|
||||
externalHooks['registered']['workflow.create'] = [hookFn];
|
||||
|
||||
await expect(externalHooks.run('workflow.create', [workflowData])).rejects.toThrow(
|
||||
ApplicationError,
|
||||
);
|
||||
await expect(externalHooks.run('workflow.create', [workflowData])).rejects.toThrow(error);
|
||||
|
||||
expect(errorReporter.error).toHaveBeenCalledWith(expect.any(ApplicationError), {
|
||||
level: 'fatal',
|
||||
|
|
|
@ -162,7 +162,10 @@ export class ExternalHooks {
|
|||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const error = new ApplicationError(`External hook "${hookName}" failed`, { cause });
|
||||
this.errorReporter.error(error, { level: 'fatal' });
|
||||
throw error;
|
||||
|
||||
// Throw original error, so that hooks control the error returned to use
|
||||
// For example on Cloud we return upgrade message when user reaches max executions or activations
|
||||
throw cause;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue