n8n/packages/workflow/src/errors/node-operation.error.ts
कारतोफ्फेलस्क्रिप्ट™ 3a2a70f193
chore: Enfore consistent file-name casing on all backend packages (#15755)
2025-05-27 16:45:50 +02:00

52 lines
1.5 KiB
TypeScript

import { NodeError } from './abstract/node.error';
import { ApplicationError } from './application.error';
import type { NodeOperationErrorOptions } from './node-api.error';
import type { INode, JsonObject } from '../interfaces';
/**
* 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 ApplicationError(error, { level: options.level ?? 'warning' });
}
super(node, error);
if (error instanceof NodeError && error?.messages?.length) {
error.messages.forEach((message) => this.addToMessages(message));
}
if (options.message) this.message = options.message;
this.level = options.level ?? 'warning';
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;
this.context.metadata = options.metadata;
if (this.message === this.description) {
this.description = undefined;
}
[this.message, this.messages] = this.setDescriptiveErrorMessage(
this.message,
this.messages,
undefined,
options.messageMapping,
);
}
}