This page provides information about error responses from the Two-Coin API and best practices for handling errors in your integration.
When an API request fails, the Two-Coin API returns a JSON error response with the following structure:
{ "error": { "code": "invalid_request", "message": "The request was invalid", "details": { "field": "source_amount", "issue": "must be greater than 0" } } }
The error object contains:
code
: A machine-readable error codemessage
: A human-readable description of the errordetails
: Additional information about the error (optional)The API uses standard HTTP status codes to indicate the success or failure of a request:
Status Code | Description |
---|---|
200 | OK - The request was successful |
400 | Bad Request - The request was invalid |
401 | Unauthorized - Authentication failed |
403 | Forbidden - The request is not allowed |
404 | Not Found - The requested resource does not exist |
429 | Too Many Requests - Rate limit exceeded |
500 | Internal Server Error - Something went wrong on our end |
Here are some common error codes you might encounter:
Error Code | Description |
---|---|
authentication_failed | Invalid authentication credentials |
invalid_request | The request parameters were invalid |
resource_not_found | The requested resource could not be found |
rate_limit_exceeded | You've exceeded the API rate limit |
offer_expired | The offer has expired and can no longer be used |
insufficient_funds | The payment provider reported insufficient funds |
payment_failed | The payment could not be processed |
invalid_address | The cryptocurrency address is invalid |
async function createOrder(orderData) { try { const response = await fetch('https://{ENDPOINT}/v1/orders', { method: 'POST', headers: { 'Content-Type': 'application/json', // Add authentication headers }, body: JSON.stringify(orderData) }); if (!response.ok) { const errorData = await response.json(); // Handle specific error cases if (errorData.error.code === 'offer_expired') { // Fetch new offers and retry return fetchOffersAndRetry(orderData); } throw new Error(`API Error: ${errorData.error.message}`); } return await response.json(); } catch (error) { console.error('Order creation failed:', error); throw error; } }
For webhook notifications, implement proper error handling to ensure you don't miss important updates:
If you encounter any issues or have questions not addressed in this documentation, please contact our support team on Telegram at https://t.me/cs_2coin (@cs_2coin).