API's response always contains a "header" or "metadata" block, named "status"
. Within that block, there is a field named "errorCode"
. If the field value is 0, the call has completed successfully. If it contains a four-digit code, an error has occurred.
For reference, all possible error codes are listed here.
As an example, an API call to add a new product (saveProduct) may return the following response:
{
"status":{
"request":"saveProduct",
"requestUnixTime":...,
"responseStatus":"error",
"errorCode":1061,
"errorField":null,
"generationTime":...,
"recordsTotal":0,
"recordsInResponse":0
},
"records":null
}
In this particular case, user does not have the permissions to add new products. (Error code 1061: No adding rights (in this module).)
We strongly encourage you to handle not only the various error codes, but also cases when your application does not receive a response at all (request timeout / empty response received / invalid JSON received). Appropriate error handling procedures may be different depending on whether the API client is an interactive application or a server-side script:
Try to draw a line between errors that are likely caused by user, or account setup, or a particular dataset — and errors which may point to flaws in application logic. User- or data-centric errors, to bring just a few examples, are:
In case of such errors, it would be best to pop up an error message to notify user about the issue, and suggest a solution if possible.
Application-logic errors, on the other hand, should be logged and reviewed by developer. These may indicate cases where the application is not following API documentation, or has made mistaken assumptions. A few examples of application-logic errors are:
Error codes 1054 and 1055 mean that current session has expired. The application should pop up a login form and ask the user to re-authenticate.