A good error response does two things: it uses the right HTTP status code (the machine-readable signal), and it returns a consistent, structured body that a developer can act on. Inconsistent error shapes are one of the biggest sources of client-side pain.
Use a standard error format: RFC 7807 (problem+json)
RFC 7807 defines a standard "problem details" body with a dedicated media type, so every error across your API looks the same:
HTTP/1.1 404 Not Found
Content-Type: application/problem+json
{
"type": "https://api.example.com/errors/not-found",
"title": "Resource not found",
"status": 404,
"detail": "No user exists with id 999",
"instance": "/users/999"
}
