From 62d1d697102df3cc85de58a2977600fa5f2d14a6 Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Tue, 28 Sep 2021 00:50:37 +0200 Subject: [PATCH] :bug: Fix n8n's behavior for empty response bodies (#2246) * Fixed n8n's behavior for empty response bodies * Correctly parsing empty bodies when expected output is a buffer --- packages/core/src/NodeExecuteFunctions.ts | 20 ++++++++++++++++++-- packages/core/src/WorkflowExecute.ts | 6 +++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index a0bef7ac0a..af9dd3ed56 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -387,15 +387,31 @@ async function proxyRequestToAxios( axios(axiosConfig) .then((response) => { if (configObject.resolveWithFullResponse === true) { + let body = response.data; + if (response.data === '') { + if (axiosConfig.responseType === 'arraybuffer') { + body = Buffer.alloc(0); + } else { + body = undefined; + } + } resolve({ - body: response.data, + body, headers: response.headers, statusCode: response.status, statusMessage: response.statusText, request: response.request, }); } else { - resolve(response.data); + let body = response.data; + if (response.data === '') { + if (axiosConfig.responseType === 'arraybuffer') { + body = Buffer.alloc(0); + } else { + body = undefined; + } + } + resolve(body); } }) .catch((error) => { diff --git a/packages/core/src/WorkflowExecute.ts b/packages/core/src/WorkflowExecute.ts index 7ebe4dcda7..df84915d75 100644 --- a/packages/core/src/WorkflowExecute.ts +++ b/packages/core/src/WorkflowExecute.ts @@ -896,7 +896,11 @@ export class WorkflowExecute { // the `error` property. for (const execution of nodeSuccessData!) { for (const lineResult of execution) { - if (lineResult.json.$error !== undefined && lineResult.json.$json !== undefined) { + if ( + lineResult.json !== undefined && + lineResult.json.$error !== undefined && + lineResult.json.$json !== undefined + ) { lineResult.error = lineResult.json.$error as NodeApiError | NodeOperationError; lineResult.json = { error: (lineResult.json.$error as NodeApiError | NodeOperationError).message,