Skip to content

Commit

Permalink
Mm/prc 0 propagate error details (#57)
Browse files Browse the repository at this point in the history
Release 5.3.2
  • Loading branch information
mmaruniak authored Feb 8, 2024
1 parent 3bbdbd4 commit bcfd990
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
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

0 comments on commit bcfd990

Please sign in to comment.