mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(Stop and Error Node): Show error message when error type is an object (#17898)
This commit is contained in:
@@ -3,9 +3,10 @@ import type {
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import { jsonParse, NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';
|
||||
import { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { createErrorFromParameters } from './utils';
|
||||
|
||||
const errorObjectPlaceholder = `{
|
||||
"code": "404",
|
||||
@@ -81,24 +82,13 @@ export class StopAndError implements INodeType {
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const errorType = this.getNodeParameter('errorType', 0) as 'errorMessage' | 'errorObject';
|
||||
const { id: workflowId, name: workflowName } = this.getWorkflow();
|
||||
const errorParameter =
|
||||
errorType === 'errorMessage'
|
||||
? (this.getNodeParameter('errorMessage', 0) as string)
|
||||
: (this.getNodeParameter('errorObject', 0) as string);
|
||||
|
||||
let toThrow: string | JsonObject;
|
||||
const { message, options } = createErrorFromParameters(errorType, errorParameter);
|
||||
|
||||
if (errorType === 'errorMessage') {
|
||||
toThrow = this.getNodeParameter('errorMessage', 0) as string;
|
||||
} else {
|
||||
const json = this.getNodeParameter('errorObject', 0) as string;
|
||||
|
||||
const errorObject = jsonParse<JsonObject>(json);
|
||||
|
||||
toThrow = {
|
||||
name: 'User-thrown error',
|
||||
message: `Workflow ID ${workflowId} "${workflowName}" has failed`,
|
||||
...errorObject,
|
||||
};
|
||||
}
|
||||
|
||||
throw new NodeOperationError(this.getNode(), toThrow);
|
||||
throw new NodeOperationError(this.getNode(), message, options);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user