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,
INodeTypeDescription,
} from 'n8n-workflow';
import { NodeConnectionType } from 'n8n-workflow';
import { NodeConnectionType, NodeOperationError } from 'n8n-workflow';
import set from 'lodash/set';
@@ -521,10 +521,22 @@ export class Redis implements INodeType {
const operation = this.getNodeParameter('operation', 0);
const returnItems: INodeExecutionData[] = [];
try {
if (operation === 'info') {
try {
const result = await client.info();
returnItems.push({ json: convertInfoToObject(result) });
} 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)
) {
@@ -532,6 +544,7 @@ export class Redis implements INodeType {
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) {
throw error;
} finally {
await client.quit();
if (this.continueOnFail()) {
returnItems.push({
json: {
error: error.message,
},
pairedItem: {
item: itemIndex,
},
});
continue;
}
await client.quit();
throw new NodeOperationError(this.getNode(), error, { itemIndex });
}
}
}
await client.quit();
return [returnItems];
}
}