Package Exports
- axios-better-stacktrace
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (axios-better-stacktrace) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
axios-better-stacktrace
Axios plugin that provides better stack traces for axios errors.
Check this axios issue for more details.
Installation
NPM
npm install axios-better-stacktrace
Yarn
yarn add axios-better-stacktrace
Note
It was tested with axios 0.21.0
.
Usage
// CommonJS
// const axiosBetterStacktrace = require('axios-better-stacktrace').default;
// ES6
import axiosBetterStacktrace from 'axios-better-stacktrace';
// use it before any other interceptors
axiosBetterStacktrace(axiosAgent);
// when using promises response error will get an enhanced stack trace automatically
axiosAgent.get('https://npmjs.com/<not-found>/').catch(enhancedError => console.error(enhancedError));
// or using async/await
(async () => {
try {
await axiosAgent.get('https://npmjs.com/<not-found>/');
} catch (enhancedError) {
console.error(enhancedError);
}
})();
// or using a response interceptor and an error callback (e.g. could be useful with a logging middleware)
axiosAgent.interceptors.response.use(config => config, enhancedError => {
console.error(enhancedError);
return result;
});
// you can restore original agent behavior if needed
const restoreAgent = axiosBetterStacktrace(axiosAgent);
// some code here...
restoreAgent();
Options
Name | Type | Default | Description |
---|---|---|---|
errorMsg | String |
Axios Better Stacktrace |
Error message to show next to the original one in the output. |
Example
Axios error without an axios-better-stacktrace plugin:
Error: Request failed with status code 500
at createError (./node_modules/axios/lib/core/createError.js:16:15)
at settle (./node_modules/axios/lib/core/settle.js:17:12)
at IncomingMessage.handleStreamEnd (./node_modules/axios/lib/adapters/http.js:244:11)
at IncomingMessage.emit (node:events:376:20)
at endReadableNT (node:internal/streams/readable:1294:12)
at processTicksAndRejections (node:internal/process/task_queues:80:21)
Axios error with an axios-better-stacktrace plugin:
Error: Request failed with status code 500
at createError (./node_modules/axios/lib/core/createError.js:16:15)
at settle (./node_modules/axios/lib/core/settle.js:17:12)
at IncomingMessage.handleStreamEnd (./node_modules/axios/lib/adapters/http.js:244:11)
at IncomingMessage.emit (node:events:376:20)
at endReadableNT (node:internal/streams/readable:1294:12)
at processTicksAndRejections (node:internal/process/task_queues:80:21)
Error: Axios Better Stacktrace
at Function.axiosBetterStacktraceMethodProxy [as patch] (./src/axiosBetterStacktrace.ts:59:41)
at ./src/axiosBetterStacktrace.spec.ts:51:19
at step (./src/axiosBetterStacktrace.spec.ts:33:23)
at Object.next (./src/axiosBetterStacktrace.spec.ts:14:53)
at ./src/axiosBetterStacktrace.spec.ts:8:71
at new Promise (<anonymous>)
at Object.<anonymous>.__awaiter (./src/axiosBetterStacktrace.spec.ts:4:12)
at Object.<anonymous> (./src/axiosBetterStacktrace.spec.ts:41:57)
at Object.asyncJestTest (./node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:106:37)
at ./node_modules/jest-jasmine2/build/queueRunner.js:45:12