Grokking ExpressJS
Vote

0% completed

​

Implementing Error Handling in Routes

Consider an async route handler that throws an error and has no try/catch around it:

app.get('/books/:id', async (req, res) => { throw new Error('Database is unavailable'); });

In Express 5, the client receives a response with status 500 Internal Server Error, Express prints the error and its stack trace to the terminal, and the server keeps running. In Express 4, the same code never sent a response, and the rejected promise could stop the whole Node.js process

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content