diff --git a/packages/nodes-base/nodes/Redis/Redis.node.ts b/packages/nodes-base/nodes/Redis/Redis.node.ts index 59d1582fdb309..ccd826eb892eb 100644 --- a/packages/nodes-base/nodes/Redis/Redis.node.ts +++ b/packages/nodes-base/nodes/Redis/Redis.node.ts @@ -4,7 +4,7 @@ import type { INodeType, INodeTypeDescription, } from 'n8n-workflow'; -import { NodeConnectionType } from 'n8n-workflow'; +import { NodeConnectionType, NodeOperationError } from 'n8n-workflow'; import set from 'lodash/set'; @@ -521,17 +521,30 @@ export class Redis implements INodeType { const operation = this.getNodeParameter('operation', 0); const returnItems: INodeExecutionData[] = []; - try { - if (operation === 'info') { + if (operation === 'info') { + try { const result = await client.info(); returnItems.push({ json: convertInfoToObject(result) }); - } else if ( - ['delete', 'get', 'keys', 'set', 'incr', 'publish', 'push', 'pop'].includes(operation) - ) { - const items = this.getInputData(); + } catch (error) { + if (this.continueOnFail()) { + returnItems.push({ + json: { + error: error.message, + }, + }); + } else { + await client.quit(); + throw new NodeOperationError(this.getNode(), error); + } + } + } else if ( + ['delete', 'get', 'keys', 'set', 'incr', 'publish', 'push', 'pop'].includes(operation) + ) { + const items = this.getInputData(); - let item: INodeExecutionData; - for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { + let item: INodeExecutionData; + for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { + try { item = { json: {}, pairedItem: { item: itemIndex } }; if (operation === 'delete') { @@ -625,14 +638,24 @@ export class Redis implements INodeType { } returnItems.push(item); } + } catch (error) { + if (this.continueOnFail()) { + returnItems.push({ + json: { + error: error.message, + }, + pairedItem: { + item: itemIndex, + }, + }); + continue; + } + await client.quit(); + throw new NodeOperationError(this.getNode(), error, { itemIndex }); } } - } catch (error) { - throw error; - } finally { - await client.quit(); } - + await client.quit(); return [returnItems]; } }