एक अच्छा error response दो चीज़ें करता है: यह सही HTTP status code इस्तेमाल करता है (machine-readable संकेत), और यह एक सुसंगत, structured body लौटाता है जिस पर एक developer क्रिया कर सके। असंगत error आकार client-side दर्द के सबसे बड़े स्रोतों में से एक हैं।
एक standard error format इस्तेमाल करें: RFC 7807 (problem+json)
RFC 7807 एक समर्पित media type के साथ एक standard "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"
}
