Skip to content

Commit 744327c

Browse files
authored
fix(core): Ensure status on Axios errors is available to the BE (#9015)
1 parent 042aa62 commit 744327c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/core/src/NodeExecuteFunctions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,11 @@ export async function proxyRequestToAxios(
848848
error.message = `${response.status as number} - ${JSON.stringify(responseData)}`;
849849
throw Object.assign(error, {
850850
statusCode: response.status,
851+
/**
852+
* Axios adds `status` when serializing, causing `status` to be available only to the client.
853+
* Hence we add it explicitly to allow the backend to use it when resolving expressions.
854+
*/
855+
status: response.status,
851856
error: responseData,
852857
response: pick(response, ['headers', 'status', 'statusText']),
853858
});

packages/core/test/NodeExecuteFunctions.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,16 @@ describe('NodeExecuteFunctions', () => {
243243
hooks.executeHookFunctions.mockClear();
244244
});
245245

246+
test('should rethrow an error with `status` property', async () => {
247+
nock(baseUrl).get('/test').reply(400);
248+
249+
try {
250+
await proxyRequestToAxios(workflow, additionalData, node, `${baseUrl}/test`);
251+
} catch (error) {
252+
expect(error.status).toEqual(400);
253+
}
254+
});
255+
246256
test('should not throw if the response status is 200', async () => {
247257
nock(baseUrl).get('/test').reply(200);
248258
await proxyRequestToAxios(workflow, additionalData, node, `${baseUrl}/test`);

0 commit comments

Comments
 (0)