fix(Splunk Node): Retry attempts if no response from API call, better error with suggestion to use Retry On Fail (#9176)

Co-authored-by: Elias Meire <elias@meire.dev>
This commit is contained in:
Michael Kret
2024-04-24 11:05:53 +03:00
committed by GitHub
parent 2bf0a3933e
commit 05a569c1cd
3 changed files with 189 additions and 21 deletions

View File

@@ -1,14 +1,16 @@
import type {
IExecuteFunctions,
ICredentialsDecrypted,
ICredentialTestFunctions,
IDataObject,
ILoadOptionsFunctions,
INodeCredentialTestResult,
INodeExecutionData,
INodeType,
INodeTypeDescription,
IRequestOptions,
import {
type IExecuteFunctions,
type ICredentialsDecrypted,
type ICredentialTestFunctions,
type IDataObject,
type ILoadOptionsFunctions,
type INodeCredentialTestResult,
type INodeExecutionData,
type INodeType,
type INodeTypeDescription,
type IRequestOptions,
NodeApiError,
NodeOperationError,
} from 'n8n-workflow';
import {
@@ -35,6 +37,7 @@ import {
} from './descriptions';
import type { SplunkCredentials, SplunkFeedResponse } from './types';
import set from 'lodash/set';
export class Splunk implements INodeType {
description: INodeTypeDescription = {
@@ -155,7 +158,7 @@ export class Splunk implements INodeType {
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: IDataObject[] = [];
const returnData: INodeExecutionData[] = [];
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
@@ -454,18 +457,30 @@ export class Splunk implements INodeType {
}
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ error: error.cause.error });
returnData.push({ json: { error: error.cause.error }, pairedItem: { item: i } });
continue;
}
throw error;
if (error instanceof NodeApiError) {
set(error, 'context.itemIndex', i);
}
if (error instanceof NodeOperationError && error?.context?.itemIndex === undefined) {
set(error, 'context.itemIndex', i);
}
throw new NodeOperationError(this.getNode(), error, { itemIndex: i });
}
Array.isArray(responseData)
? returnData.push(...(responseData as IDataObject[]))
: returnData.push(responseData as IDataObject);
if (Array.isArray(responseData)) {
for (const item of responseData) {
returnData.push({ json: item, pairedItem: { item: i } });
}
} else {
returnData.push({ json: responseData, pairedItem: { item: i } });
}
}
return [this.helpers.returnJsonArray(returnData)];
return [returnData];
}
}