feat(Redis Node): Add support for continue on fail / error output branch (#11714)

This commit is contained in:
Jon
2024-12-10 15:58:19 +00:00
committed by GitHub
parent b37e5142b2
commit ed359586c8

View File

@@ -4,7 +4,7 @@ import type {
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeConnectionType } from 'n8n-workflow'; import { NodeConnectionType, NodeOperationError } from 'n8n-workflow';
import set from 'lodash/set'; import set from 'lodash/set';
@@ -521,17 +521,30 @@ export class Redis implements INodeType {
const operation = this.getNodeParameter('operation', 0); const operation = this.getNodeParameter('operation', 0);
const returnItems: INodeExecutionData[] = []; const returnItems: INodeExecutionData[] = [];
try { if (operation === 'info') {
if (operation === 'info') { try {
const result = await client.info(); const result = await client.info();
returnItems.push({ json: convertInfoToObject(result) }); returnItems.push({ json: convertInfoToObject(result) });
} else if ( } catch (error) {
['delete', 'get', 'keys', 'set', 'incr', 'publish', 'push', 'pop'].includes(operation) if (this.continueOnFail()) {
) { returnItems.push({
const items = this.getInputData(); 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; let item: INodeExecutionData;
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
try {
item = { json: {}, pairedItem: { item: itemIndex } }; item = { json: {}, pairedItem: { item: itemIndex } };
if (operation === 'delete') { if (operation === 'delete') {
@@ -625,14 +638,24 @@ export class Redis implements INodeType {
} }
returnItems.push(item); 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]; return [returnItems];
} }
} }