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

Mm/prc 0 propagate error details #57

Merged
merged 3 commits into from
Feb 8, 2024
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)

## [5.3.2] - 2024-02-08

### Fixed

Error details of external HTTP error resposes are propagated correctly

## [5.3.1] - 2023-10-25

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lambda-essentials-ts",
"version": "5.3.1",
"version": "5.3.2",
"description": "A selection of the finest modules supporting authorization, API routing, error handling, logging and sending HTTP requests.",
"main": "lib/index.js",
"private": false,
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function serializeAxiosError(error: AxiosError): SerializedAxiosError | u
const { status, data } = error.response;
return {
status: data.originalStatusCode ?? status, // Propagate original status code of ClientException
details: data.details ? data.details : data, // Prevent wrapping of Exception
details: data.details && Object.keys(data.details).length > 0 ? data.details : data, // Prevent wrapping of Exception
};
}

Expand Down
30 changes: 30 additions & 0 deletions tests/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,36 @@ describe('Util', () => {
const serializedError = serializeAxiosError(error as any);
expect(serializedError).toEqual(expected);
});

test('serializes non-Exception objects which also have "details" field', () => {
const expected = {
details: {
details: {},
error,
},
status: 500,
};

const axiosErrorWithNonExceptionError: AxiosError = {
isAxiosError: true,
message: 'test-message',
response: {
data: {
details: {},
error,
},
status: 500,
config: {},
headers: null,
statusText: 'test-status-text',
},
config: {},
name: 'test-name',
toJSON: () => ({}),
};
const serializedError = serializeAxiosError(axiosErrorWithNonExceptionError as any);
expect(serializedError).toEqual(expected);
});
});

describe('redactSecret', () => {
Expand Down
Loading