Skip to main content

Error Codes

All API errors follow a consistent format for easy handling and debugging.

Error Response Format​

{
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid chain ID: 999999",
"details": {
"field": "fromChain",
"value": "999999"
}
}
}

Common Error Codes​

CodeHTTP StatusDescription
VALIDATION_ERROR400Invalid request parameters
UNSUPPORTED_CHAIN400Chain not supported
INSUFFICIENT_LIQUIDITY404No routes found with sufficient liquidity
TOKEN_NOT_FOUND404Token address not recognized
TRANSACTION_NOT_FOUND404Transaction hash not found
RATE_LIMIT_EXCEEDED429Too many requests
INTERNAL_ERROR500Server error
SERVICE_UNAVAILABLE503Service temporarily unavailable

Error Handling Best Practices​

1. Always Check Response Status​

async function getQuote(params) {
try {
const response = await fetch('https://xplore.api.v2.routerprotocol.com/v1/quote?' + new URLSearchParams(params));

if (!response.ok) {
const error = await response.json();
throw new Error(error.error?.message || 'Quote request failed');
}

return await response.json();
} catch (error) {
console.error('Quote error:', error);
throw error;
}
}

2. Handle Specific Error Codes​

try {
const quote = await getQuote(params);
} catch (error) {
if (error.error?.code === 'INSUFFICIENT_LIQUIDITY') {
// Show user-friendly message
console.log('No routes available for this swap');
} else if (error.error?.code === 'RATE_LIMIT_EXCEEDED') {
// Implement retry logic
console.log('Rate limit exceeded, please wait');
} else {
// Handle other errors
console.error('Unexpected error:', error);
}
}

3. Validate Input Before Request​

function validateQuoteParams(params) {
if (!params.fromChain || !params.toChain) {
throw new Error('Chain IDs are required');
}
if (!params.fromToken || !params.toToken) {
throw new Error('Token addresses are required');
}
if (!params.fromAmount || parseFloat(params.fromAmount) <= 0) {
throw new Error('Valid amount is required');
}
return true;
}

HTTP Status Codes​

Success Codes​

CodeDescription
200 OKRequest successful
201 CreatedResource created successfully

Client Error Codes​

CodeDescription
400 Bad RequestInvalid request parameters
401 UnauthorizedMissing or invalid API key
403 ForbiddenAccess denied
404 Not FoundResource not found
429 Too Many RequestsRate limit exceeded

Server Error Codes​

CodeDescription
500 Internal Server ErrorServer error
502 Bad GatewayUpstream service error
503 Service UnavailableService temporarily unavailable
504 Gateway TimeoutRequest timeout