fix(core): Return original hooks errors to the frontend (#13365)

This commit is contained in:
Mutasem Aldmour 2025-02-19 14:23:01 +01:00 committed by GitHub
parent 966d60a39a
commit 5439181e92
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View file

@ -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',

View file

@ -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;
}
}
}