mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import type { INode, JsonObject } from '@/Interfaces';
|
|
import type { NodeOperationErrorOptions } from './node-api.error';
|
|
import { NodeError } from './abstract/node.error';
|
|
|
|
/**
|
|
* Class for instantiating an operational error, e.g. an invalid credentials error.
|
|
*/
|
|
export class NodeOperationError extends NodeError {
|
|
type: string | undefined;
|
|
|
|
constructor(
|
|
node: INode,
|
|
error: Error | string | JsonObject,
|
|
options: NodeOperationErrorOptions = {},
|
|
) {
|
|
if (error instanceof NodeOperationError) {
|
|
return error;
|
|
}
|
|
if (typeof error === 'string') {
|
|
error = new Error(error);
|
|
}
|
|
|
|
super(node, error);
|
|
|
|
if (error instanceof NodeError && error?.messages?.length) {
|
|
error.messages.forEach((message) => this.addToMessages(message));
|
|
}
|
|
|
|
if (options.message) this.message = options.message;
|
|
if (options.level) this.level = options.level;
|
|
if (options.functionality) this.functionality = options.functionality;
|
|
if (options.type) this.type = options.type;
|
|
this.description = options.description;
|
|
this.context.runIndex = options.runIndex;
|
|
this.context.itemIndex = options.itemIndex;
|
|
|
|
if (this.message === this.description) {
|
|
this.description = undefined;
|
|
}
|
|
|
|
[this.message, this.messages] = this.setDescriptiveErrorMessage(
|
|
this.message,
|
|
this.messages,
|
|
undefined,
|
|
options.messageMapping,
|
|
);
|
|
}
|
|
}
|