mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -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.
|
* 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
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