Error Handling

Error handling is all about dealing with responses from the API when something goes wrong.

Each error response from the API contains a HTTP status code and a message that describes what went wrong.

There are 5 HTTP statuses returned from the API:

  1. HTTP status code: 200 – OK. Every thing is OK
  2. HTTP status code: 401 – Unauthorized. OAuth 2 credentials are not valid
  3. HTTP status code: 403 – Forbidden. You are not allowed access the resource you are trying to access
  4. HTTP status code: 404 – Not found. The resource you are looking for cannot be found
  5. HTTP status code: 500 – Internal server error. We messed up! The request you made could not be serviced because of something we did wrong on the server
You can refer to the official specification for more information on what these status codes mean. The status codes are all defined in section 10.

The first of the responses above (HTTP status code: 200) does not need to be handled as it is not an error. However, if you get any of the other response codes (HTTP status codes: 401, 403, 404 and 500)  it means that something went wrong and you may want to handle the error response it in your code.

An error response is sent with the HTTP status code in the header of the response and the body contains an error message which gives some details about what went wrong and why.

The error message that is sent in the body of the response is structured as a JSON object and will look something like:

{“errorMessage”:”Oops you are not permitted to view this object (12345) because it belongs to someone else.”}