medium10 pts · first answer countsapi-designexpresserror-handling
Cannot set headers after they are sent
This route logs 'Cannot set headers after they are sent to the client' when amount is missing. What is the bug?
app.post('/pay', (req, res) => {
if (!req.body.amount) {
res.status(400).json({ error: 'amount required' })
}
res.status(201).json(createPayment(req.body))
})Discussion 0
Join free to post in the discussion.
Related questions
- Response for a successful DELETEBackend Developer
- A product page removed for goodBackend Developer
- Signing up with a taken usernameBackend Developer
- Calling DELETE on a read-only routeBackend Developer
- A client posts XML to a JSON APIBackend Developer
- URL for one productBackend Developer
- Telling the client where the new item livesBackend Developer
- Filtering and sorting a listBackend Developer