Extending error object in express, but Debug does only show the stack trace
See original GitHub issueHello,
Small question of which I don’t know it’s a bug or expected behaviour:
In my express application I have the following app.use at the bottom:
app.use( (error, req, res, next) => {
const status = error.statusCode || 500;
const source = error.source || 'Unknown';
const message = error.message;
const info = error.info || '';
console.log(error); // For logging on the server
res.status(status).json({
status: status,
source: source,
message: message,
info: info
})
});
This shows me the stack trace and the error object (with source and info properties).
When I change the console.log to debug, it only shows the stack trace and not the error object.
Why is that? And how can I show the error object with the debug command also?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Re-throwing exception in NodeJS and not losing stack trace
The problem with creating a new Error is you can lose metadata that was attached to the original Error that was thrown, the...
Read more >Custom errors, extending Error - The Modern JavaScript Tutorial
Our function readUser(json) will not only read JSON, but check (“validate”) the data. If there are no required fields, or the format is...
Read more >Best Practices for Node.js Error-handling - Toptal
Using Node.js built-in Error object is a good practice because it includes intuitive and clear information about errors like StackTrace, which most developers ......
Read more >A Guide to Error Handling in Express.js | Scout APM Blog
Mishandled errors can lead to a bad UX and negatively affect your ... client with the error's status code, message, and even the...
Read more >Error handling - Apollo GraphQL Docs
Your resolvers can also throw errors in situations where Apollo Server doesn't ... The stacktrace error field is useful while developing and debugging...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Aha, I thought this got fixed a while back. Apparently not. Thanks for the repro case, by the way 😃
The first argument is not
util.format
’d where it should be.The standard
.toString()
onError
objects does not include extraneous information.console.log()
is, more or less, just(...args) => stdout.write(util.format(...args))
. That’s why it’s showing the extra information.For now, use a format string:
This will get fixed in the future.
I get the same behaviour using the
make-error-cause
package: