refactor(core): Separate API response from error in execution error causes (no-changelog) (#7880)
Store the third-party API response error separately from the error stored as `cause` Follow-up to: https://github.com/n8n-io/n8n/pull/7820#discussion_r1406009154
This commit is contained in:
@@ -2,16 +2,16 @@ import type { Functionality, IDataObject, JsonObject, Severity } from '../../Int
|
||||
import { ApplicationError } from '../application.error';
|
||||
|
||||
interface ExecutionBaseErrorOptions {
|
||||
cause?: Error | JsonObject;
|
||||
cause?: Error;
|
||||
errorResponse?: JsonObject;
|
||||
}
|
||||
|
||||
export abstract class ExecutionBaseError extends ApplicationError {
|
||||
description: string | null | undefined;
|
||||
|
||||
/**
|
||||
* @tech_debt Ensure `cause` can only be `Error` or `undefined`
|
||||
*/
|
||||
cause: Error | JsonObject | undefined;
|
||||
cause?: Error;
|
||||
|
||||
errorResponse?: JsonObject;
|
||||
|
||||
timestamp: number;
|
||||
|
||||
@@ -23,7 +23,7 @@ export abstract class ExecutionBaseError extends ApplicationError {
|
||||
|
||||
functionality: Functionality = 'regular';
|
||||
|
||||
constructor(message: string, { cause }: ExecutionBaseErrorOptions) {
|
||||
constructor(message: string, { cause, errorResponse }: ExecutionBaseErrorOptions = {}) {
|
||||
const options = cause instanceof Error ? { cause } : {};
|
||||
super(message, options);
|
||||
|
||||
@@ -35,6 +35,8 @@ export abstract class ExecutionBaseError extends ApplicationError {
|
||||
} else if (cause && !(cause instanceof Error)) {
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
if (errorResponse) this.errorResponse = errorResponse;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
|
||||
@@ -38,8 +38,12 @@ export abstract class NodeError extends ExecutionBaseError {
|
||||
node: INode;
|
||||
|
||||
constructor(node: INode, error: Error | JsonObject) {
|
||||
const message = error instanceof Error ? error.message : '';
|
||||
super(message, { cause: error });
|
||||
if (error instanceof Error) {
|
||||
super(error.message, { cause: error });
|
||||
} else {
|
||||
super('', { errorResponse: error });
|
||||
}
|
||||
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user