axios-better-stacktrace
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -5,2 +5,9 @@ # Changelog | ||
### [2.0.1](https://github.com/svsool/axios-better-stacktrace/compare/v2.0.0...v2.0.1) (2021-02-14) | ||
### Bug Fixes | ||
* Eject interceptor on calling restore ([923eb45](https://github.com/svsool/axios-better-stacktrace/commit/923eb45a47bd4b632ea063f6691f0685e21e5653)) | ||
## [2.0.0](https://github.com/svsool/axios-better-stacktrace/compare/v1.2.0...v2.0.0) (2021-02-14) | ||
@@ -7,0 +14,0 @@ |
import { AxiosInstance } from 'axios'; | ||
declare const patchedSym: unique symbol; | ||
declare module 'axios' { | ||
interface AxiosInstance { | ||
[patchedSym]?: boolean; | ||
} | ||
interface AxiosRequestConfig { | ||
@@ -4,0 +8,0 @@ topmostError?: Error; |
@@ -16,3 +16,3 @@ "use strict"; | ||
var isAxiosError = function (error) { | ||
return error instanceof Error && error.isAxiosError !== undefined; | ||
return error instanceof Error && error.isAxiosError; | ||
}; | ||
@@ -29,5 +29,4 @@ var axiosMethods = [ | ||
]; | ||
// inherits original axios handler generics https://github.com/axios/axios/blob/79979d9214601478b67a330fc144cad25c59f3c7/index.d.ts#L139-L146 | ||
var axiosBetterStacktraceHandler = function (params, topmostError) { | ||
// extends request config with topmostError, so it could be used inside an interceptor to enhance original error | ||
// extend request config with topmostError, so it could be used inside an interceptor to enhance original error | ||
switch (params.method) { | ||
@@ -74,4 +73,4 @@ case 'request': { | ||
}; | ||
// enhance original error with a topmostError stack trace | ||
axiosInstance.interceptors.response.use(undefined, function (error) { | ||
// enhance original response error with a topmostError stack trace | ||
var responseErrorInterceptorId = axiosInstance.interceptors.response.use(undefined, function (error) { | ||
if (isAxiosError(error) && error.config && error.config.topmostError instanceof Error) { | ||
@@ -133,9 +132,9 @@ error.originalStack = error.stack; | ||
}); | ||
// ensure consumer of the plugin can restore original handlers | ||
var restoreOriginalHandlers = function () { | ||
// ensure consumer of the plugin can restore original handlers and remove custom interceptor | ||
return function () { | ||
axiosInstance.interceptors.response.eject(responseErrorInterceptorId); | ||
Object.assign(axiosInstance, originalHandlers); | ||
}; | ||
return restoreOriginalHandlers; | ||
}; | ||
exports.default = axiosBetterStacktrace; | ||
//# sourceMappingURL=axiosBetterStacktrace.js.map |
@@ -14,3 +14,3 @@ { | ||
"author": "Svyatoslav Sobol <svyatoslav.sobol@gmail.com>", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"main": "lib/axiosBetterStacktrace.js", | ||
@@ -17,0 +17,0 @@ "types": "lib/axiosBetterStacktrace.d.ts", |
@@ -58,2 +58,9 @@ # axios-better-stacktrace | ||
}); | ||
// you can restore original agent behavior if needed | ||
const restoreAgent = axiosBetterStacktrace(axiosAgent); | ||
// some code here... | ||
restoreAgent(); | ||
``` | ||
@@ -60,0 +67,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17763
152
109