Skip to content

Commit

Permalink
fix: Remove Axios config from connection errors
Browse files Browse the repository at this point in the history
To avoid filling the logs with unnecessary information
  • Loading branch information
gnarea committed Nov 17, 2020
1 parent b493bd6 commit e94e60a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/lib/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,14 @@ describe('deliverParcel', () => {
);
});

test('Unexpected axios exceptions should be wrapped rethrown', async () => {
test('Connection error should be replaced with a simpler error', async () => {
// .. That doesn't leak the request or response.
// @ts-ignore
stubAxiosPost.mockReset();
const axiosError = new Error('Haha, in thy face');
stubAxiosPost.mockRejectedValueOnce(axiosError);

const expectedError = new PoHTTPError(axiosError, 'Failed to deliver parcel');
const expectedError = new PoHTTPError(`Connection error: ${axiosError.message}`);
await expectPromiseToReject(deliverParcel(url, body), expectedError);
});

Expand Down
4 changes: 2 additions & 2 deletions src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ async function postRequest(
});
} catch (error) {
if (!error.response) {
throw new PoHTTPError(error, 'Failed to deliver parcel');
throw new PoHTTPError(`Connection error: ${error.message}`);
}

const responseStatus = error.response.status;
const reason = error.response?.data?.message;
const reason = error.response.data?.message;
if (responseStatus === 403) {
throw new PoHTTPInvalidParcelError(
reason ? `Server refused to accept parcel: ${reason}` : 'Server refused to accept parcel',
Expand Down

0 comments on commit e94e60a

Please sign in to comment.