Errors
v1 and v2 report most errors in the response body, while v3 uses HTTP status codes. In every version, check both the HTTP status and the body.
v1 and v2
Responses include succeed. When a request fails, succeed is false and message describes the
error:
Error response
These errors, including invalid parameters and failed authentication, have HTTP status 200, so
check succeed, not just the status. In the API reference, they are the default response of
each endpoint.
Error messages
| Message | Reason |
|---|---|
Unauthorized (token expired) | Authentication failed. See Handling errors. |
<endpoint> not supported | v1 has no endpoint with that name. Endpoint names are case-sensitive. |
Unknown method | v2 has no endpoint with that path. |
empty content | The v2 request body is empty. Send {} when the endpoint takes no parameters. |
An invalid or expired token returns a message that starts with Unauthorized. A token for another
product, an unexpected error, or a v1 request with an empty body returns a generic message with an
incident ID:
Error response
Other messages describe what was wrong with the request. They are in English and can change, so do not build logic on their exact text.
HTTP error status
A few errors have an HTTP error status and a body without succeed:
| HTTP status | Reason |
|---|---|
| 404 | The Authorization header is missing or malformed, or the API version in the path is unknown |
| 429 | Too many requests. See Request rate. |
| 500 | The request could not be processed |
For example, a request with a malformed Authorization header returns:
Error response
v3
v3 returns errors with an HTTP status code and a JSON body with code and message. code is the
HTTP status as a string:
Error response
| HTTP status | Reason |
|---|---|
| 400 | A parameter is invalid, or the endpoint is unknown |
| 401 | Authentication failed, for example the token has expired |
| 403 | No permission for the resource |
| 404 | The resource was not found |
| 429 | Too many requests at the same time. The body is not JSON. |
| 500 | Unexpected error. message includes an incident ID. |
| 501 | The endpoint does not support the request |
Each endpoint in the API reference lists the statuses it can return. A request without an
Authorization header, or with a header that is not a Bearer token, returns HTTP status 400
without a JSON body.
Handling errors
- Check the HTTP status before you parse the body. Responses from the web server, such as HTTP status 413 for a request body that is too large and 429 for too many requests, are not JSON.
- If authentication fails, check your credentials. A
Bearer token expires after 15 minutes, so request a
new one when it does. For an invalid or expired token, v1 and v2 return
succeed: falsewith amessagethat starts withUnauthorized, and v3 returns HTTP status 401. For a token created for another product, v1 and v2 returnsucceed: falsewith the generic incident ID message. - HTTP status 429 means you sent requests too fast. Wait before you send the next one, and stay within the request rate limits.
- Do not retry other errors without changing the request, as an invalid request fails again. Some
requests, such as
deliveries/batch-send, create something each time, so retrying one after a timeout can send the mail twice. - If an error has an incident ID, include it when you report the error to LianaMailer support.