> ## Documentation Index
> Fetch the complete documentation index at: https://docs-api.dexchange.sn/llms.txt
> Use this file to discover all available pages before exploring further.

# Error Handling

> Learn about DExchange API error codes and how to handle them

# Error Handling

DExchange API uses conventional HTTP response codes to indicate the success or failure of API requests. Here's a comprehensive guide to our error codes and how to handle them.

## HTTP Status Codes

| Status Code | Description                                                   |
| ----------- | ------------------------------------------------------------- |
| 200         | Success - The request was processed successfully              |
| 201         | Created - The resource was created successfully               |
| 400         | Bad Request - Invalid request parameters or validation failed |
| 401         | Unauthorized - Invalid or missing API key                     |
| 403         | Forbidden - Valid API key but insufficient permissions        |
| 404         | Not Found - The requested resource doesn't exist              |
| 429         | Too Many Requests - Rate limit exceeded                       |
| 500         | Internal Server Error - Something went wrong on our end       |

## Error Response Format

```json theme={null}
{
  "message": ["Error description"],
  "success": false
}
```

## Common Error Scenarios

### Authentication Errors

```json theme={null}
{
  "message": ["Invalid API KEY"],
  "success": false
}
```

### Validation Errors

```json theme={null}
{
  "message": ["Amount should not exceed 1,000,000 FCFA"],
  "success": false
}
```

### Transaction Errors

```json theme={null}
{
  "message": ["Invalid transactionId or OTP expired"],
  "success": false
}
```

## Best Practices for Error Handling

1. **Always Check Response Status**

   * Verify HTTP status code before processing response
   * Handle both success and error cases

2. **Implement Retry Logic**

   * Retry failed requests with exponential backoff
   * Only retry idempotent operations
   * Respect rate limits

3. **Log Error Details**

   * Store error responses for debugging
   * Include transaction IDs in logs
   * Monitor error patterns

4. **User-Friendly Messages**

   * Display appropriate error messages to end-users
   * Translate technical errors into user-friendly language
   * Provide clear next steps when possible

5. **Security Considerations**
   * Never expose sensitive information in error messages
   * Validate all input data
   * Handle timeouts gracefully

## Maintenance Mode

When the API is under maintenance:

```json theme={null}
{
  "message": ["DEXCHANGE-API is under maintenance"],
  "success": false
}
```

## Rate Limiting

* Requests are limited per API key
* Rate limit headers included in responses
* Implement proper backoff when limits are reached

## Support

If you encounter persistent errors or need assistance:

* Check our [API Reference](/api-reference)
* Contact support at [team@dexchange.sn](mailto:team@dexchange.sn)
* Include relevant transaction IDs and error messages
