સારો error response બે વસ્તુ કરે છે: તે યોગ્ય HTTP status code (machine-readable સંકેત) વાપરે છે, અને એક સુસંગત, structured body પરત કરે છે જેના પર developer કાર્ય કરી શકે. અસંગત error આકારો client-side પીડાના સૌથી મોટા સ્રોતોમાંનો એક છે.
પ્રમાણભૂત error format વાપરો: 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"
}
