-
Notifications
You must be signed in to change notification settings - Fork 114
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
instanceof HttpError not working when receiving error from other package #56
Comments
Thanks for your report! It sounds like you may be describing this Node.js issue with how node_modules and instanceof interact: nodejs/node#17943 |
Thanks for the quick answer! Yes, that would probably be an issue too. But this StackOverflow question makes me think it can even happen with the same versions. Just different instances of the module, due to how npm works. I could solve this by checking the
But it gets a bit harder if I want to know if it's a HttpError or a generic Error. So I will be looking into why npm isn't flattening the node_modules. |
Related: npm/npm#19770 I've found I can work around it by running Unfortunately, the npm team seems to have moved to Discourse for their issues. Well, that's not what's unfortunate, but the issue is now locked, without a solution, and I can't find it in their forum anywhere. You can close this issue if you want. I'll be playing around with different npm versions (mine is 5.7.1) and see what I can find out. |
Hi @petermorlion thanks for the additional info. I usually don't close it out unless it's turned stale. You raise a valid issue, but I'm just not sure if it's possible for this module to solve, but open to ideas on if it can be and what the changes may look like 👍 |
@dougwilson I have the same problem, cause i need to distinguish between generic Error and HttpError So far i am also using Then the check can look like: What do you think? |
Hi @eugef yes, the errors do have a name you can check. The name will be reliable as long as you do not minify the code. The check would look like this: |
I know this is an old issue, but just wanted to comment if you're around: I've been working to clean through these issues, and this remained open because I felt like we should try and do something. Thinking back, perhaps we can provide an export |
I'm not sure if this is specific to http-errors or to TypeScript, but this is the issue I'm having: it seems that
instanceof
doesn't work when I'm receiving aHttpError
from another package.To reproduce:
npm init
npm install typescript http-errors --save
npm install @types/http-errors --save-dev
index.ts
:To have exactly the same as I did, run
./node_modules/typescript/bin/tsc --init
and changetarget
fromes5
toes6
.Now run
npm link
in the directory and create a new project somewhere else andnpm link <first-package-name>
to add a symlink in thenode_modules
directory.In the new project, add some code like this:
Again, I'm not sure if this is TypeScript in general, or the way the code in http-errors is contructed. I'm no JS/TS expert, so I'm interested in your opinion/advice.
For your convenience, I've created a repo that you can just pull and then run
node index.js
.The text was updated successfully, but these errors were encountered: