| | import { isObjectLiteral } from '@n8n/backend-common'; |
| | import { NodeOperationError } from 'n8n-workflow'; |
| | import type { Workflow } from 'n8n-workflow'; |
| |
|
| | |
| | |
| | |
| | const errorProperties = ['description', 'stack', 'executionId', 'workflowId']; |
| |
|
| | export function objectToError(errorObject: unknown, workflow: Workflow): Error { |
| | |
| | if (errorObject instanceof Error) { |
| | |
| | return errorObject; |
| | } else if ( |
| | isObjectLiteral(errorObject) && |
| | 'message' in errorObject && |
| | typeof errorObject.message === 'string' |
| | ) { |
| | |
| | let error: Error | undefined; |
| | if ( |
| | 'node' in errorObject && |
| | isObjectLiteral(errorObject.node) && |
| | typeof errorObject.node.name === 'string' |
| | ) { |
| | const node = workflow.getNode(errorObject.node.name); |
| |
|
| | if (node) { |
| | error = new NodeOperationError( |
| | node, |
| | errorObject as unknown as Error, |
| | errorObject as object, |
| | ); |
| | } |
| | } |
| |
|
| | if (error === undefined) { |
| | error = new Error(errorObject.message); |
| | } |
| |
|
| | for (const field of errorProperties) { |
| | if (field in errorObject && errorObject[field]) { |
| | |
| | (error as unknown as Record<string, unknown>)[field] = errorObject[field]; |
| | } |
| | } |
| |
|
| | return error; |
| | } else { |
| | |
| | return new Error('An error occurred'); |
| | } |
| | } |
| |
|