좋은 error response는 두 가지를 한다: 올바른 HTTP status code(기계가 읽는 신호)를 쓰고, 개발자가 대응할 수 있는 일관되고 구조화된 body를 반환한다. 일관성 없는 error 형태는 client 측 고통의 가장 큰 원천 중 하나다.
표준 error 형식을 쓰라: RFC 7807 (problem+json)
RFC 7807은 전용 media type을 가진 표준 "problem details" body를 정의하므로, API 전반의 모든 error가 똑같아 보인다:
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"
}
