From 362442ae68ad076b016eb3e8be8f61a6fadb41de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Tue, 2 Apr 2024 09:41:25 +0200 Subject: [PATCH 1/2] fix(core): Ensure `status` on Axios errors is available to the BE --- packages/core/src/NodeExecuteFunctions.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index 51f66c1574572..1f61e51b23e97 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -848,6 +848,11 @@ export async function proxyRequestToAxios( error.message = `${response.status as number} - ${JSON.stringify(responseData)}`; throw Object.assign(error, { statusCode: response.status, + /** + * Axios adds `status` when serializing, causing `status` to be available only to the client. + * Hence we add it explicitly to allow the backend to use it when resolving expressions. + */ + status: response.status, error: responseData, response: pick(response, ['headers', 'status', 'statusText']), }); From 268f938cdd01d44acc9a80f7c6bcad8476f8d508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Tue, 2 Apr 2024 09:42:19 +0200 Subject: [PATCH 2/2] Add test --- packages/core/test/NodeExecuteFunctions.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/core/test/NodeExecuteFunctions.test.ts b/packages/core/test/NodeExecuteFunctions.test.ts index 92f23782189d4..c9d4865b8b220 100644 --- a/packages/core/test/NodeExecuteFunctions.test.ts +++ b/packages/core/test/NodeExecuteFunctions.test.ts @@ -243,6 +243,16 @@ describe('NodeExecuteFunctions', () => { hooks.executeHookFunctions.mockClear(); }); + test('should rethrow an error with `status` property', async () => { + nock(baseUrl).get('/test').reply(400); + + try { + await proxyRequestToAxios(workflow, additionalData, node, `${baseUrl}/test`); + } catch (error) { + expect(error.status).toEqual(400); + } + }); + test('should not throw if the response status is 200', async () => { nock(baseUrl).get('/test').reply(200); await proxyRequestToAxios(workflow, additionalData, node, `${baseUrl}/test`);