Explore Library
Code QuizAdvanced

API Error Response Status Bug

Spot the mistake in how this REST endpoint reports a not-found error.

Codejavascript
app.get('/api/v1/users/:id', (req, res) => {
  const user = db.findUser(req.params.id);

  if (!user) {
    return res.json({
      error: 'User not found'
    });
  }

  return res.status(200).json({ data: user });
});

What is the bug in how this endpoint handles the missing-user case?