Skip to content

Commit

Permalink
fix(error): make sure error.config is defined in the errorLogger (#110)
Browse files Browse the repository at this point in the history
Sometimes, axios throws an error without `error.config`, this makes sure
we don’t destructure an undefined property.

Related: axios/axios#4665
Fix #94

Co-authored-by: Haegul Pyun <phg2491@gmail.com>
  • Loading branch information
tusbar and hg-pyun committed May 7, 2022
1 parent d1ed70e commit cf68d60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/logger/__test__/error.spec.js
Expand Up @@ -28,6 +28,14 @@ test('response should be return immutable axiosError', () => {
expect(mockLogger).toReturnWith(axiosError);
});

test('if erorr.config is undefined, return original error', () => {
const error = new Error('Unexpected error');

const mockLogger = jest.fn(errorLoggerWithoutPromise);
mockLogger(error);
expect(mockLogger).toReturnWith(error);
});

test('if config is undefined, logger make default log', () => {
const {
config: { url, method },
Expand Down
3 changes: 3 additions & 0 deletions src/logger/error.ts
Expand Up @@ -4,6 +4,9 @@ import { assembleBuildConfig } from '../common/config';
import StringBuilder from '../common/string-builder';

function errorLoggerWithoutPromise(error: AxiosError, config: ErrorLogConfig = {}) {
if (!error.config) {
return error
}

const {config: { method, baseURL, params, url }, response} = error;

Expand Down

0 comments on commit cf68d60

Please sign in to comment.