Grokking ExpressJS
Vote

0% completed

​

Handling Errors and Logging with Morgan and Winston

This error handler looks complete, yet the log line it writes says nothing about the error:

const logger = winston.createLogger({ format: winston.format.json(), transports: [new winston.transports.Console()], }); app.use((err, req, res, next) => { logger.error(err); res.status(500).json({ error: 'Internal Server Error' }); });
{"level":"error"}

The message and the stack trace are gone, because Winston's JSON format copies only an object's own enumerable properties, and an Error keeps message and stack in properties that are not enumerable

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content