-
Notifications
You must be signed in to change notification settings - Fork 135
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
Exception from hook not handled #257
Comments
It's intended behavior that the error appears again from the listener function. Internally the error gets caught and thrown again. This makes it possible to correlate the Node.js HTTP request with the error handled by Fortune.js. That looks like how errors are meant to be handled. After throwing an error there's nothing more that can be done, what Fortune.js will do is immediately end the transaction if there is one and reject the request. |
Thank you very much for your answer |
One more thing, even if I catch the error on this line
I can still see
in the logs. Also if I replace this line
by this one
I can see in the logs the error twice.
|
That would probably be a bug somewhere in your application code. The tests for const server = http.createServer((request, response) =>
listener(request, response)
.catch(error => stderr.error(error))) Is it possible that the framework you're using for |
I'm using
|
Hmm, maybe you could try two things:
|
The problem remains the same. I tried :
and I get
|
I can't reproduce the warning you're getting, throwing errors is working fine. Can you tell me which version you're using? |
I think I'm using the latest version
|
@thomasthiebaud I tried to reproduce your issue with a similar code and did not get the uncaught exception, with node v7.2.0 : And your stack trace seems weird: As you can see this line do not throw a BadRequestError with a "Invalid status" message. Is it your complete stack trace ? this error seems to be thrown in the application code you shared earlier in the issue, we only see fortune |
You are right, the stack trace is strange. I will try to investigate on this strange stack trace next week. Thank you very much for your feedbacks. |
@thomasthiebaud did you ever find the cause of the warnings? I'm getting the same thing:
with very similar code as you (using The warnings are also reproducible with https://github.com/redoPop/fortunejs-example/. Debug notes: Trace when using
If I comment out the re-throw in
|
Hi @cooperka, what should I do to reproduce exactly ? (with your example repository) |
OK, I'll do a more thorough investigation then, the interesting part is |
@kketch with that example repo, simply start the server and hit it with any invalid request that causes some sort of error to be thrown and you'll see the warnings in your console. @daliwali to add more info, it looks like the follow-up warning is thrown in |
I found the problem: the listener returns a promise that doesn't get a const server = http.createServer((request, response) =>
listener(request, response)
// Make sure to catch Promise rejections.
.catch(error => {
console.error(error.stack)
})) I'm not sure what to do about it. I think it's somewhat unexpected for there to be a return value from the listener, I guess I could remove it but it would be a breaking change. Or I can make sure that this listener never throws. Though I would be in favor of removing it and bumping major version, not sure what I was thinking with this, it makes dealing with HTTP-specific requests easier but it's kind of unexpected. |
Hmm, in my opinion it makes sense as-is, no changes to the libraries needed -- I updated my server code to match your example above and it works great! If you're good with it, I'm happy to make a PR to that example app to encourage others to follow the same pattern. I see now that this pattern is already in an example in the official guide, I just hadn't noticed the difference and blindly followed the boilerplate app. Thank you for your help! |
I would like to validate my request (get, post, update or delete), and if the request is not valid, I would like to return an error (status 400 or 500 depending on the error). For the moment I'm using hooks for this task like this
The important line here is
throw new BadRequestError('Invalid status');
. This line makes fortune returning a 400 error withinvalid status
as a content.Even if I get the desire response, it seems that the error is not fully catch, and so I also get the error in the catch of the listener.
So here are my questions:
The text was updated successfully, but these errors were encountered: