fix(FTP Node): Continue of fail looping support with paired item (#8659)

This commit is contained in:
Michael Kret 2024-02-19 18:21:32 +02:00 committed by GitHub
parent bee17dd6cc
commit 3279762221
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,7 +18,7 @@ import type {
INodeTypeDescription,
JsonObject,
} from 'n8n-workflow';
import { formatPrivateKey } from '@utils/utilities';
import { formatPrivateKey, generatePairedItemData } from '@utils/utilities';
interface ReturnFtpItem {
type: string;
@ -515,6 +515,8 @@ export class Ftp implements INodeType {
}
let ftp: ftpClient;
let sftp: sftpClient;
try {
try {
if (protocol === 'sftp') {
sftp = new sftpClient();
@ -544,8 +546,17 @@ export class Ftp implements INodeType {
password: credentials.password as string,
});
}
} catch (error) {
if (this.continueOnFail()) {
const pairedItem = generatePairedItemData(items.length);
return [[{ json: { error: error.message }, pairedItem }]];
}
throw error;
}
for (let i = 0; i < items.length; i++) {
try {
const newItem: INodeExecutionData = {
json: items[i].json,
binary: {},
@ -658,7 +669,10 @@ export class Ftp implements INodeType {
await sftp!.put(uploadData, remotePath);
} else {
// Is text file
const buffer = Buffer.from(this.getNodeParameter('fileContent', i) as string, 'utf8');
const buffer = Buffer.from(
this.getNodeParameter('fileContent', i) as string,
'utf8',
);
await sftp!.put(buffer, remotePath);
}
@ -777,7 +791,10 @@ export class Ftp implements INodeType {
}
} else {
// Is text file
const buffer = Buffer.from(this.getNodeParameter('fileContent', i) as string, 'utf8');
const buffer = Buffer.from(
this.getNodeParameter('fileContent', i) as string,
'utf8',
);
try {
await ftp!.put(buffer, remotePath);
} catch (error) {
@ -797,6 +814,14 @@ export class Ftp implements INodeType {
returnItems = returnItems.concat(executionData);
}
}
} catch (error) {
if (this.continueOnFail()) {
returnItems.push({ json: { error: error.message }, pairedItem: { item: i } });
continue;
}
throw error;
}
}
if (protocol === 'sftp') {
@ -810,10 +835,6 @@ export class Ftp implements INodeType {
} else {
await ftp!.end();
}
if (this.continueOnFail()) {
return [[{ json: { error: error.message } }]];
}
throw error;
}