Skip to content

Commit

Permalink
feat(Redis Node): Add support for continue on fail / error output bra…
Browse files Browse the repository at this point in the history
…nch (#11714)
  • Loading branch information
Joffcom authored Dec 10, 2024
1 parent b37e514 commit ed35958
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions packages/nodes-base/nodes/Redis/Redis.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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];
}
}

0 comments on commit ed35958

Please sign in to comment.