Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving axios error detection #5

Closed
icrotz opened this issue Mar 10, 2021 · 2 comments
Closed

Improving axios error detection #5

icrotz opened this issue Mar 10, 2021 · 2 comments

Comments

@icrotz
Copy link

icrotz commented Mar 10, 2021

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch axios-better-stacktrace@2.0.2 for the project I'm working on.

Inside a typescript project the net.js library don't always throw error as instances or errors.
The instanceof keyword can failed during the check.

Here is the diff that solved my problem:

diff --git a/node_modules/axios-better-stacktrace/lib/axiosBetterStacktrace.js b/node_modules/axios-better-stacktrace/lib/axiosBetterStacktrace.js
index f16af8e..91678fd 100644
--- a/node_modules/axios-better-stacktrace/lib/axiosBetterStacktrace.js
+++ b/node_modules/axios-better-stacktrace/lib/axiosBetterStacktrace.js
@@ -12,8 +12,11 @@ var __assign = (this && this.__assign) || function () {
 };
 Object.defineProperty(exports, "__esModule", { value: true });
 var patchedSym = Symbol('axiosBetterStacktrace.patched');
+var isError = function (error) {
+  return Object.prototype.toString.call(error) === "[object Error]";
+}
 var isAxiosError = function (error) {
-    return error instanceof Error && error.isAxiosError;
+    return (error instanceof Error || isError(error)) && error.isAxiosError;
 };
 var axiosMethods = [
     'request',

This issue body was partially generated by patch-package.

@svsool
Copy link
Owner

svsool commented Mar 11, 2021

Hi, I'd appreciate repro steps along with the patch, I assume you use different vmcontexts that break instanceof operator?

svsool added a commit that referenced this issue Mar 13, 2021
@svsool
Copy link
Owner

svsool commented Mar 13, 2021

Fixed in v2.1.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants