@condor-labs/axios
Version:
This module provide and useful helper to use the official Axios library.
35 lines (28 loc) • 792 B
JavaScript
// Improve axios stack traces https://github.com/axios/axios/issues/2387
const request = (config) => {
config.errorContext = new Error("Thrown at:");
return config;
};
const response = (error) => {
// TODO: replace with Node v14 modern syntax when all apps are upgraded
// const originalStackTrace = error.config?.errorContext?.stack;
// if (originalStackTrace) {
// error.stack = `${error.stack}\n${originalStackTrace}`;
// }
if (
error &&
error.config &&
error.config.errorContext &&
error.config.errorContext.stack
) {
const originalStackTrace = error.config.errorContext.stack;
if (originalStackTrace) {
error.stack = `${error.stack}\n${originalStackTrace}`;
}
}
throw error;
};
module.exports = {
request,
response,
};