From 922eb2cb5c136ebd350d70d0bf9f7651af2b90a4 Mon Sep 17 00:00:00 2001 From: mmaruniak Date: Thu, 8 Feb 2024 11:38:32 +0100 Subject: [PATCH 1/3] Propagate details of erros only when not empty --- src/util.ts | 2 +- tests/util.test.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/util.ts b/src/util.ts index af958da..0e4dc68 100644 --- a/src/util.ts +++ b/src/util.ts @@ -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 }; } diff --git a/tests/util.test.ts b/tests/util.test.ts index 5a78004..2a60f1b 100644 --- a/tests/util.test.ts +++ b/tests/util.test.ts @@ -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', () => { From dece09b24dc1634cde64a3bf3cc028950ab3011c Mon Sep 17 00:00:00 2001 From: mmaruniak Date: Thu, 8 Feb 2024 11:45:33 +0100 Subject: [PATCH 2/3] Release 5.3.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index df96ef4..630c810 100644 --- a/package.json +++ b/package.json @@ -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, From ec518b0ba83c4fa0f1d7097904274bd2081be784 Mon Sep 17 00:00:00 2001 From: mmaruniak Date: Thu, 8 Feb 2024 13:37:24 +0100 Subject: [PATCH 3/3] Update change log --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2de5084..f3faa97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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