Quiz Entry - updated: 2026.07.14
What HTTP status code should you return for invalid input?
Return 400 Bad Request whenever the client sends invalid or malformed input.
if (!isValidInput(req.query)) {
res.status(400);
res.type('application/json');
res.send(JSON.stringify({ error: 'Invalid input' }));
return;
}
Common status codes:
| Code | Meaning | Use Case |
|---|---|---|
| 200 | OK | Successful request |
| 201 | Created | Resource created (POST) |
| 400 | Bad Request | Invalid input |
| 401 | Unauthorized | Not authenticated |
| 403 | Forbidden | Not authorized |
| 404 | Not Found | Resource doesn't exist |
| 500 | Server Error | Unexpected server problem |
Tip: Always return appropriate status codes - clients depend on them to handle responses correctly.