Handling exceptions
The API may return the following http statuses
200 - Standard response for successful HTTP requests.
201 - The request has been fulfilled, resulting in the creation of a new resource.
301 - Redirect
302 - Redirect
400 - Most frequent status a frontend developer can be faced with. Common status in case of invalid input provided or logical error.
401 - The Authorization http headers missed.
403 - The user has no permissions to access the resource
404 - The resource doesn't exist
405 - The resource doesn't accept requests with this http method
409 - Indicates that the request could not be processed because of conflict in the current state of the resource.
You can get this code in case of duplicated request. For example, if you're trying to create a user that already exists.
429 - Some resources limit how many requests you can do within a defined time frame. E.g. 5 requests per minute. If the rate limit is exceed, the API returns http 429 status code.
500 - Something is broken on the server. We've got a notification at an error-tracking service. Will be fixed soon.
502 - Something is very broken on the server. Probably, we don't know about the incident. It's better to manually report about the problem to the backend team.
Errors format
Every client error (http status >= 400 && http status < 500) returns json object.
The json object contains type, detail, and fallback_message fields.
There are 2 types of errors: connected with a specific field or non-field errors.
If the error is connected with a field, you can find the field name as a key inside of the detail.
If the error is not connected with a specific field, you'll find the descriptions of the error in detail.non_field_errors.
A value of the fallback_message field is auto-generated and may not always be suitable for end users.
You shouldn't rely on the value of this field.
This way, client developers can always fallback and show this message when the client receives an error that is not handled.
Example of an error object:
{
"type": "ValidationError",
"detail": {
"email": [
"Email is already registered."
],
"non_field_errors": [
"Profile can not be registered."
]
},
"fallback_message": "Profile can not be registered."
}
Error types
Possible values of the type field.
ValidationError
Input data is invalid.
PermissionDenied
The user has no permissions to access the resource
IntegrityError
You can get this code in case of duplicated request. For example, if you're trying to create a user that already exists.
Throttled
Some resources limit how many requests you can do within a defined time frame. E.g. 5 requests per minute. If the rate limit is exceed, the API returns this type of error and http 429 status code.
Client-side package
Feel free to use the following client-side packages in your code.