Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Ensure status on Axios errors is available to the BE #9015

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/core/src/NodeExecuteFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
});
Expand Down
10 changes: 10 additions & 0 deletions packages/core/test/NodeExecuteFunctions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down
Loading