Y
Y
Yevgeni2018-07-28 20:52:49
Python
Yevgeni, 2018-07-28 20:52:49

What is the best way to return error information from rest api? Invent your own error codes or?

What is the best way to return error information from rest api? Invent some error codes or?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
roswell, 2018-07-29
@roswell

Or use the standard ones:
200 OK (request processed, food served)
400 Bad Request (nonsense came in the request) or 413 Request Payload Too Large (for that rare case, if too much nonsense came in the request)
403 Forbidden (no access to the resource, missing or invalid auth token or something like that)
404 Not Found or 410 Gone(everything seems to be clear here, but there may be ambiguity - either the required endpoint is missing, or there is nothing to return. It is still better to react from 404 to the missing (from 410 to the one that existed, but now missing forever) endpoint, and if not the requested data was found, then according to the situation - either 200 with an empty response, or 400 or 413)
405 Method Not Allowed (for example, if GET was sent instead of PUT, well, this is with the classic implementation of the REST API; it may not be necessary if everything goes through POST along with some "action": "make-me-coffee")
500 Internal Server Error or 503 Service Unavailable
(We're closed here right now, but tomorrow we'll be waiting from 9:00 GMT. Or maybe we won't, but you hang on)
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question