mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
fix(core): Prevent NodeErrors from being wrapped multiple times (#8301)
This commit is contained in:
parent
64ceb16af6
commit
b267bf07e3
|
@ -35,16 +35,16 @@ const COMMON_ERRORS: IDataObject = {
|
|||
* a value recursively inside an error object.
|
||||
*/
|
||||
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) {
|
||||
if (error instanceof Error) {
|
||||
super(error.message, { cause: error });
|
||||
} else {
|
||||
super('', { errorResponse: error });
|
||||
}
|
||||
|
||||
this.node = node;
|
||||
const isError = error instanceof Error;
|
||||
const message = isError ? error.message : '';
|
||||
const options = isError ? { cause: error } : { errorResponse: error };
|
||||
super(message, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
16
packages/workflow/test/errors/node.error.test.ts
Normal file
16
packages/workflow/test/errors/node.error.test.ts
Normal 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);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue