Error Handling¶
The Crossing Minds API is using multiple level of error identification. This allows clients to implement both simple management system together with a fine error handling.
At the highest level errors are identified by the HTTP status code;
More specific identification can be implemented from the
error_code
in the payload;Even more specific identification can be implemented from the
error_data.name
in the payload.
Example¶
Let’s use the following request as an example, attempting to create or update three items:
$ curl -X PUT https://api.crossingminds.com/items-bulk/ -s \
-H "Authorization: Bearer $JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{ \
"items": [ \
{"item_id": "11111", "price": 9.99, "tags": ["family", "sci-fi"]}, \
{"item_id": "22222", "price": 5.19, "tags": ["drama", "sci-fi"]}, \
{"item_id": "11111", "price": 4.49, "tags": ["family"]} \
]}'
With such a request, you might receive the following error as a response:
HTTP/2 400
content-type: application/json
vary: Accept, Origin
allow: GET, HEAD, OPTIONS
date: Wed, 1 Jan 2020 20:00:00 GMT
via: 1.1 google
alt-svc: clear
{
"error_code": 42,
"error_name": "DuplicatedError",
"message": "The item 11111 is duplicated",
"error_data": {
"type": "item",
"key": 11111,
"name": "DUPLICATED_ITEM_ID"
}
}
This response has an HTTP status code 400 Bad Request, which indicates a request error. We should not retry the request but instead look deeper for find what is wrong.
the payload has an
error_code
of42
which indicates DuplicatedError.the payload has an
error_data.name
ofDUPLICATED_ITEM_ID
telling us that some item ID is duplicated in the request. Indeed it is an error to attempt creating the same item multiple times in the same request.
List of Errors¶
In this document you will find all possible error codes and their description.
ServerError¶
The server encountered an internal error. You may be able to retry your request, but this usually indicates an error on the API side that require support.
HTTP Status Code |
|
error_code |
|
TooManyRequests¶
The amount of requests exceeds the limit of your subscription.
HTTP Status Code |
|
error_code |
|
error_data.name |
|
error_data |
|
AuthError¶
Cannot perform authentication.
HTTP Status Code |
|
error_code |
|
error_data.name |
|
error_data |
|
JwtTokenExpired¶
The JWT token has expired. You should get a new token using the refresh token.
HTTP Status Code |
|
error_code |
|
error_data.name |
|
RefreshTokenExpired¶
The refresh token has expired. Be sure to update your update the refresh token every time you use it.
HTTP Status Code |
|
error_code |
|
error_data.name |
|
WrongData¶
There is an error in the submitted data.
HTTP Status Code |
|
error_code |
|
error_data.name |
|
error_data |
|
DuplicatedError¶
Some resource is duplicated.
HTTP Status Code |
|
error_code |
|
error_data.name |
|
error_data |
|
ForbiddenError¶
You do not have enough permissions to access this resource.
HTTP Status Code |
|
error_code |
|
error_data.name |
|
error_data |
|
NotFoundError¶
Some resource does not exist.
HTTP Status Code |
|
error_code |
|
error_data.name |
|
error_data |
|
MethodNotAllowed¶
The HTTP method is not allowed.
HTTP Status Code |
|
error_code |
|
error_data.name |
|