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:
{
"message": "Invalid request: from_currency is required"
}The error response contains:
message: A human-readable description of the errorThe 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 messages you might encounter:
| Error Type | Example Message |
|---|---|
| Authentication Error | Invalid signature or Merchant not found |
| Invalid Request | Invalid request: from_currency is required |
| Not Found | Not found: Order with code xyz not found |
| Bad Request | Bad request: Invalid wallet address |
| Provider Error | Provider error: Amount below minimum |
| Internal Error | Internal server error: ... |
async function createOrder(orderData) {
try {
const response = await fetch('https://api.dev2coin.space/api/on_ramp/orders', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-MERCHANT-CODE': merchantCode,
'X-TIMESTAMP': Date.now().toString(),
'X-SIGNATURE': generateSignature(...)
},
body: JSON.stringify(orderData)
});
if (!response.ok) {
const errorData = await response.json();
// Handle specific error cases based on status code
if (response.status === 400) {
// Invalid request - check the message for details
console.error('Invalid request:', errorData.message);
} else if (response.status === 401) {
// Authentication failed - check signature generation
console.error('Auth failed:', errorData.message);
}
throw new Error(`API Error: ${errorData.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).