Catching errors
Sometimes, the REST API will return an error. For example, you will get an error if your access token is expired or if you omitted a required parameter. Your code can automatically retry the request when it gets an error other than 400 Bad Request, 401 Unauthorized, 403 Forbidden, and 404 Not Found. If an API error occurs even after retries, the API throws an error that includes the HTTP status code of the response (response.status) and the response headers (response.headers). Handle these errors in your code. For example, use a try/catch block to catch errors.
Rate limit errors
If you receive a rate limit error, you may want to retry your request after waiting. When you are rate limited, the API responds with a 503 Service Unavailable or 429 Too Many Requests error. Retry your request after an appropriate amount of time.