fix(core): Prevent NodeErrors from being wrapped multiple times (#8301)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2024-01-16 16:18:34 +01:00 committed by GitHub
parent 64ceb16af6
commit b267bf07e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 9 deletions

View file

@ -35,16 +35,16 @@ const COMMON_ERRORS: IDataObject = {
* a value recursively inside an error object. * a value recursively inside an error object.
*/ */
export abstract class NodeError extends ExecutionBaseError { export abstract class NodeError extends ExecutionBaseError {
node: INode; constructor(
readonly node: INode,
error: Error | JsonObject,
) {
if (error instanceof NodeError) return error;
constructor(node: INode, error: Error | JsonObject) { const isError = error instanceof Error;
if (error instanceof Error) { const message = isError ? error.message : '';
super(error.message, { cause: error }); const options = isError ? { cause: error } : { errorResponse: error };
} else { super(message, options);
super('', { errorResponse: error });
}
this.node = node;
} }
/** /**

View file

@ -0,0 +1,16 @@
import { mock } from 'jest-mock-extended';
import type { INode } from '@/Interfaces';
import { NodeApiError } from '@/errors/node-api.error';
import { NodeOperationError } from '@/errors/node-operation.error';
describe('NodeError', () => {
const node = mock<INode>();
it('should prevent errors from being re-wrapped', () => {
const apiError = new NodeApiError(node, mock({ message: 'Some error happened', code: 500 }));
const opsError = new NodeOperationError(node, mock());
expect(new NodeOperationError(node, apiError)).toEqual(apiError);
expect(new NodeOperationError(node, opsError)).toEqual(opsError);
});
});