# Errors

SwitchApp returns a standardized response format for every request. This format indicates when a request completes successfully and when it fails. A standard SwitchApp response consists of a **`status`**, **`message`**, **`data`** and  **`errors`** object. These are accompanied by a corresponding HTTP response code:&#x20;

* Codes in the `2xx` range indicate success.
* Codes in the `4xx` range indicate an error. Usually, a failed request will indicate the reason for failure in its message (e.g., *unauthorized access - API key absent*,  *a required parameter was omitted*, etc.).
* Codes in the `5xx` range indicate an error with SwitchApp's servers (these rarely occur, but should be reported to us when encountered).

Along with error codes, the **`errors`** object is helpful if the request fails initial validation. The object consists of properties whose names indicate the failed fields while their values are string arrays containing all the validation failures. This eases client-side form validation.

{% hint style="info" %}
**NOTE:** Always structure your code to handle API errors and exceptions thrown from our library eg by checking the response status before attempting to consume the data, or by using a handled try-catch block. This will ensure your application does not crash when a validation error occurs or an exception is thrown.
{% endhint %}
