-
Notifications
You must be signed in to change notification settings - Fork 36
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
"Unhandled Error" for errors that have been handled properly. #54
Comments
yup, hit this as well |
Thank you for providing more information, I am understanding the problem better now. As I see it, there are two parts
As for 1), we have deliberately decided to always print all errors, nothing's changing there. As for 2), I agree that prefixing the log message with "Unhandled error" is misleading. I am proposing to change the message to Thoughts? |
I don't know if this is related, but using promises in remotes also generates this type of error
spews out Nope, sorry, I very definitely handled the error ;) |
Rejecting a promise with an error is the same as calling This may be subjective, but your code did not handle the error, it merely passed it down the I don't want to argue about wording and definitions. See my earlier #54 (comment) for an actionable proposal. |
ok, so I'm coming back to this because I am confused ;) Doesn't take a lot... how am I supposed to return the error to the browser from my remote method using promises ?
|
Your code looks correct to me. The remote method returns a promise that's eventually rejected, strong-remoting will treat this rejection as an error and strong-error-handler will convert this error into an HTTP error response (and log a message). |
Same here, |
just bumped on this problem. Any other workarounds? I've been looking even at page 2 of google and no joy. Still getting the annoying
Dependencies
|
See my earlier #54 (comment) for an actionable proposal.
Any volunteers to contribute that change? |
Published the changes in |
I'm aware of the changes introduced in
"final:after": {
"./middlewares/skipHandledErrors": {}, <<<<<<<<<<<<<< put this line here
"strong-error-handler": {}
} Create the module.exports = function() {
return function skipHandledErrors(err, req, res, next) {
return err.hasBeenHandled ? null : next(err);
};
}; Now, for each error you handle explicitly, just add a property MyModel.afterRemoteError('prototype.doSomething', async function(ctx) {
if (ctx.error.statusCode === 401) {
ctx.res.redirect('http://www.myapp.com/login');
ctx.error.hasBeenHandled = true;
return;
}
throw ctx.error;
}); it's not ideal but it's not the end of the world either. |
See #40
This needs to be reopened and checked over.
My comment at the bottom shows that this bug is still present.
When we're writing remote methods on our models and explicitly returning an error with a statusCode and a message back up to the client, strong-error-handler should not be saying that there is an Unhandled Error, as we are clearly handling it with our methods, by the method defined in the loopback docs
Maybe if I get some free time later this week I can look into it, but for now one of the dedicated devs should really check this out.
Using the latest, loopback 3.6.0 locally and strongloop 6.0.3 globally.
Proposal from @bajtos on how to fix this issue - see #54 (comment)
As I see it, there are two parts
statusCode
property)As for 1), we have deliberately decided to always print all errors, nothing's changing there.
As for 2), I agree that prefixing the log message with "Unhandled error" is misleading. I am proposing to change the message to
Request {verb} {path} failed: {error}
- see https://github.com/strongloop/strong-error-handler/blob/323cd4dfbffa3425d6d6bd00bd9ba93fbede5342/lib/logger.jsThis issue is waiting for a volunteer to open a pull request and make the proposed change.
The text was updated successfully, but these errors were encountered: