2 ms·
I like to return a error code property for each particular error case in the JSON body of the response. This allows you to determine exactly where in the code t
by Rezo 11y ago
I like to return a error code property for each particular error case in the JSON body of the response. This allows you to determine exactly where in the code the error is from, and also allows the client to do fine-grained error handling in the UI if required. I've also found it incredibly useful to include a unique error ID with each request that is also logged server side, so that you can pinpoint the request in your logs and look up the context including previous and next requests.
It looks something like this:
HTTP 403
{
errorCode: 403102,
message: "Missing required permission: IN_SOCIAL_NETWORK",
id: "064d6a1f-ba30-47de-8975-c319f01729ca"
}