Skip to content

Commit

Permalink
fix: avoid errors during logging of requests/responses (#188)
Browse files Browse the repository at this point in the history
Fixes #179

This commit slightly modifies how requests and responses
are logged when debug logging is enabled to avoid
any JSON marshalling type errors.
We no longer use JSON.stringify() to format
the request and response objects, as they
actually aren't needed because the
logger.debug() and logger.error() functions
can handle objects just fine and do a decent job
of pretty-printing them.
  • Loading branch information
padamstx authored Jan 18, 2022
1 parent 60f5013 commit d05ea1a
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions lib/request-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,45 +132,25 @@ export class RequestWrapper {
this.axiosInstance.interceptors.request.use(
(config) => {
logger.debug('Request:');
try {
logger.debug(JSON.stringify(config, null, 2));
} catch {
logger.error(config);
}

logger.debug(config);
return config;
},
(error) => {
logger.error('Error: ');
try {
logger.error(JSON.stringify(error, null, 2));
} catch {
logger.error(error);
}

logger.error(error);
return Promise.reject(error);
}
);

this.axiosInstance.interceptors.response.use(
(response) => {
logger.debug('Response:');
try {
logger.debug(JSON.stringify(response, null, 2));
} catch {
logger.error(response);
}

logger.debug(response);
return response;
},
(error) => {
logger.error('Error: ');
try {
logger.error(JSON.stringify(error, null, 2));
} catch {
logger.error(error);
}

logger.error(error);
return Promise.reject(error);
}
);
Expand Down

0 comments on commit d05ea1a

Please sign in to comment.