Skip to content
RED SAG Skills
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))
})
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions