Common HTTP Errors
Here’s a quick reference table of common HTTP errors you might encounter when using the Straddle API:Status Code | Error Type | Description | Common Causes |
---|---|---|---|
400 | Bad Request | The request was unacceptable, often due to missing a required parameter. |
|
401 | Unauthorized | No valid API key provided. |
|
403 | Forbidden | The API key doesn’t have permissions to perform the request. |
|
404 | Not Found | The requested resource doesn’t exist. |
|
422 | Unprocessable Entity | The request was well-formed but was unable to be followed due to semantic errors. |
|
429 | Too Many Requests | Too many requests hit the API too quickly. |
|
500 | Internal Server Error | Something went wrong on Straddle’s end. |
|
Understanding HTTP Status Codes
Straddle uses standard HTTP status codes to indicate the success or failure of an API request. Here are the main categories:- 2xx: Success
- 4xx: Client errors
- 5xx: Server errors
Common Error Responses
When an error occurs, Straddle returns a JSON object with details about the error. The structure of this object is consistent across all error types:Types of Errors
400 Bad Request
This error occurs when the request is malformed or contains invalid parameters. Example response:- Check your request parameters for any missing or invalid values.
- Ensure all required fields are included and formatted correctly.
401 Unauthorized
This error occurs when authentication fails, typically due to an invalid API key. Example response:- Verify that you’re using the correct API key.
- Check if your API key has been revoked or expired.
- Ensure you’re using the correct environment (test vs. production).
403 Forbidden
This error occurs when the authenticated user doesn’t have permission to perform the requested action. Example response:- Check if the authenticated account has the necessary permissions.
- If you’re using a platform account, ensure you’ve correctly specified the
Straddle-Account-Id
header.
404 Not Found
This error occurs when the requested resource doesn’t exist. Example response:- Verify that you’re using the correct resource ID.
- Check if the resource has been deleted or hasn’t been created yet.
422 Unprocessable Entity
This error occurs when the request is well-formed, but contains invalid data. Example response:- Review the error message for specific details about which parameter is invalid.
- Adjust your request data accordingly.
429 Too Many Requests
This error occurs when you’ve exceeded the rate limit for API requests. Example response:- Implement exponential backoff and retry logic in your application.
- Consider optimizing your code to make fewer API requests.
500 Internal Server Error
This error indicates an unexpected condition on the server side. Example response:- Implement a retry mechanism with exponential backoff.
- If the error persists, contact Straddle support and provide the Request-Id and Correlation-Id.
Best Practices for Error Handling
- Always check the HTTP status code: Don’t assume a request was successful. Always check the HTTP status code before processing the response.
- Parse the error response: Extract the error details from the JSON response to get more information about what went wrong.
- Log errors with context: When logging errors, include relevant context such as the Request-Id, Correlation-Id, and any pertinent request details.
- Implement retry logic: For transient errors (like rate limiting or temporary server issues), implement a retry mechanism with exponential backoff.
- Provide meaningful error messages to users: Translate API errors into user-friendly messages in your application’s UI.
- Monitor error rates: Keep track of the frequency and types of errors you’re encountering to identify and address recurring issues.