ఒక మంచి error response రెండు పనులు చేస్తుంది: సరైన HTTP status code (machine-readable సంకేతం)ను వాడుతుంది, మరియు ఒక developer చర్య తీసుకోగల స్థిరమైన, నిర్మాణాత్మక bodyను తిరిగి ఇస్తుంది. అస్థిరమైన error ఆకృతులు client-వైపు బాధకు అతిపెద్ద మూలాలలో ఒకటి.
ఒక 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"
}
