diff --git a/packages/nodes-base/nodes/Splunk/GenericFunctions.ts b/packages/nodes-base/nodes/Splunk/GenericFunctions.ts index 731bd1808f..5d463efaf5 100644 --- a/packages/nodes-base/nodes/Splunk/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Splunk/GenericFunctions.ts @@ -6,7 +6,7 @@ import type { IRequestOptions, IHttpRequestMethods, } from 'n8n-workflow'; -import { NodeApiError } from 'n8n-workflow'; +import { NodeApiError, NodeOperationError, sleep } from 'n8n-workflow'; import { parseString } from 'xml2js'; @@ -139,9 +139,29 @@ export async function splunkApiRequest( delete options.qs; } + let result; try { - return await this.helpers.request(options).then(parseXml); + let attempts = 0; + + do { + try { + const response = await this.helpers.request(options); + result = await parseXml(response); + return result; + } catch (error) { + if (attempts >= 5) { + throw error; + } + await sleep(1000); + attempts++; + } + } while (true); } catch (error) { + if (result === undefined) { + throw new NodeOperationError(this.getNode(), 'No response from API call', { + description: "Try to use 'Retry On Fail' option from node's settings", + }); + } if (error?.cause?.code === 'ECONNREFUSED') { throw new NodeApiError(this.getNode(), { ...(error as JsonObject), code: 401 }); } diff --git a/packages/nodes-base/nodes/Splunk/Splunk.node.ts b/packages/nodes-base/nodes/Splunk/Splunk.node.ts index c25d70f83f..2e220fe1f7 100644 --- a/packages/nodes-base/nodes/Splunk/Splunk.node.ts +++ b/packages/nodes-base/nodes/Splunk/Splunk.node.ts @@ -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 { 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]; } } diff --git a/packages/nodes-base/nodes/Splunk/splunk.svg b/packages/nodes-base/nodes/Splunk/splunk.svg index 8e79edc812..8eb25b4a26 100644 --- a/packages/nodes-base/nodes/Splunk/splunk.svg +++ b/packages/nodes-base/nodes/Splunk/splunk.svg @@ -1 +1,134 @@ - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +