n8n/packages/workflow/src/errors/node-operation.error.ts
कारतोफ्फेलस्क्रिप्ट™ 65c5609ab5
feat(core): Use WebCrypto to generate all random numbers and strings (#9786)
2024-06-19 13:33:57 +02:00

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,
);
}
}