# Error Handling

When an API request fails, Blueink returns a structured JSON response to help you identify and resolve the issue.

## Error Response Format
All error responses (400, 401, 403, 404, 409, 429, 500) follow a consistent format:

```json
{
  "errorMessage": "A human-readable description of the error",
  "errorCode": "E_CODE_NAME",
  "fieldErrors": {
    "field_name": ["List of errors for this specific field"]
  }
}
```

- **`errorMessage`**: A clear explanation of what went wrong.
- **`errorCode`**: A machine-readable string identifying the error type.
- **`fieldErrors`**: (Optional) For 400 Bad Request errors, this object contains validation errors for specific input fields.

## Common Error Codes

| Error Code | Description |
| :--- | :--- |
| `INVALID_DATA` | One or more fields in the request body failed validation. |
| `MISSING_REQUIRED` | A required field was not provided. |
| `NOT_FOUND` | The specified resource ID does not exist. |
| `PERMISSION_DENIED` | Your API key does not have access to this resource. |
| `LIMIT_EXCEEDED` | You have reached your account's usage or rate limits. |
| `CONFLICT` | The request could not be completed due to a conflict with the current state of the resource. |

## Best Practices
- Always check the `errorCode` for automated error handling.
- Log the `errorMessage` and `fieldErrors` for debugging purposes.
- Implement retry logic with exponential backoff for `503` or `429` errors.
