Error Handling
Learn how to handle errors from the Web3 Pay API. All errors follow a consistent format with actionable error codes.
Error Response Format
All API errors return a JSON response with this structure:
{
"success": false,
"error": {
"code": "INVALID_WALLET_ADDRESS",
"message": "The provided wallet address is not valid for ethereum network",
"details": {
"wallet_address": "0xinvalid",
"network": "ethereum"
}
}
}HTTP Status Codes
| Status | Description |
|---|---|
| 200 | Success - Request completed successfully |
| 400 | Bad Request - Invalid parameters or request body |
| 401 | Unauthorized - Invalid or missing API key |
| 403 | Forbidden - Insufficient permissions |
| 404 | Not Found - Resource doesn't exist |
| 429 | Too Many Requests - Rate limit exceeded |
| 500 | Server Error - Something went wrong on our end |
Error Codes Reference
Authentication Errors (401)
MISSING_API_KEYAPI key not provided in request headers
Solution: Include X-API-Key header with your API key
INVALID_API_KEYThe provided API key is invalid or revoked
Solution: Check your API key is correct and not revoked
EXPIRED_API_KEYThe API key has expired
Solution: Generate a new API key in the dashboard
Authorization Errors (403)
INSUFFICIENT_PERMISSIONSAPI key lacks required permission for this endpoint
Solution: Use a key with appropriate permissions or update key permissions
CONNECT_NOT_READYStripe Connect account is not set up or pending verification
Solution: Complete Stripe Connect onboarding in the dashboard
ACCOUNT_SUSPENDEDYour account has been suspended
Solution: Contact support@web3pay.io for assistance
Validation Errors (400)
VALIDATION_ERRORRequest body contains invalid or missing fields
Solution: Check the error details for specific field issues
INVALID_WALLET_ADDRESSWallet address is invalid for the specified network
Solution: Verify the address format matches the target network
UNSUPPORTED_CURRENCYThe requested cryptocurrency is not supported
Solution: Use a supported currency (ETH, USDC, USDT, MATIC)
UNSUPPORTED_NETWORKThe specified network is not supported
Solution: Use a supported network (ethereum, polygon, base)
AMOUNT_TOO_LOWTransaction amount is below the minimum ($10)
Solution: Increase the amount to at least $10
AMOUNT_TOO_HIGHTransaction amount exceeds your plan limit
Solution: Reduce amount or upgrade your plan for higher limits
INVALID_METADATAMetadata object contains invalid data types
Solution: Ensure metadata values are strings, numbers, or booleans
Resource Errors (404)
SESSION_NOT_FOUNDThe specified session ID does not exist
Solution: Verify the session_id is correct
TRANSACTION_NOT_FOUNDThe specified transaction ID does not exist
Solution: Verify the transaction ID is correct
API_KEY_NOT_FOUNDThe specified API key ID does not exist
Solution: Verify the key ID is correct
Session Errors (400)
SESSION_EXPIREDThe onramp session has expired
Solution: Create a new session (sessions expire after 30 minutes)
SESSION_ALREADY_USEDThe session has already been completed or failed
Solution: Create a new session for another transaction
QUOTE_EXPIREDThe price quote has expired
Solution: Create a new session to get an updated quote
Rate Limit Errors (429)
RATE_LIMITEDToo many requests - rate limit exceeded
Solution: Wait and retry after the Retry-After header duration
Server Errors (500)
INTERNAL_ERRORAn unexpected error occurred
Solution: Retry the request. If persistent, contact support.
SERVICE_UNAVAILABLEService is temporarily unavailable
Solution: Retry after a few minutes
Handling Errors in Code
1400">import { Web3Pay } 400">from 400">039;@web3pay/sdk039;;2 3400">const client = 400">new Web3Pay({ apiKey: 400">039;wp3_live_sk_...039; });4 5400">async 400">function createPurchase(walletAddress, amount) {6 400">try {7 400">const session = 400">await client.createSession({8 walletAddress,9 cryptoCurrency: 400">039;ETH039;,10 fiatAmount: amount,11 fiatCurrency: 400">039;USD039;12 });13 400">return session;14 } 400">catch (error) {15 500">// Handle specific error codes16 400">switch (error.code) {17 400">case 400">039;INVALID_WALLET_ADDRESS039;:18 showError(400">039;Please enter a valid Ethereum wallet address039;);19 400">break;20 21 400">case 400">039;AMOUNT_TOO_LOW039;:22 showError(400">039;Minimum purchase amount is $10039;);23 400">break;24 25 400">case 400">039;AMOUNT_TOO_HIGH039;:26 showError(400">039;Amount exceeds your daily limit039;);27 400">break;28 29 400">case 400">039;CONNECT_NOT_READY039;:30 500">// Redirect to complete setup31 window.location.href = 400">039;/dashboard/connect039;;32 400">break;33 34 400">case 400">039;RATE_LIMITED039;:35 500">// Retry after delay36 400">const retryAfter = error.retryAfter || 60;37 showError(400">`Too many requests. Please 400">try again in ${retryAfter}s`);38 400">break;39 40 400">default:41 500">// Generic error handling42 showError(400">039;Something went wrong. Please 400">try again.039;);43 console.error(400">039;API Error:039;, error);44 }45 }46}Retry Logic
Some errors are transient and can be retried. Here's a recommended approach:
400">async 400">function withRetry(fn, maxRetries = 3) {
400">let lastError;
for (400">let attempt = 1; attempt <= maxRetries; attempt++) {
400">try {
400">return 400">await fn();
} 400">catch (error) {
lastError = error;
500">// Don039;t retry client errors (except rate limits)
400">if (error.status >= 400 && error.status < 500 && error.code !== 400">039;RATE_LIMITED039;) {
400">throw error;
}
500">// Don400">039;t retry on last attempt
400">if (attempt === maxRetries) {
400">throw error;
}
500">// Calculate delay (exponential backoff)
400">const delay = error.code === 039;RATE_LIMITED039;
? (error.retryAfter || 60) * 1000
: Math.min(1000 * Math.pow(2, attempt), 30000);
400">await 400">new Promise(resolve => setTimeout(resolve, delay));
}
}
400">throw lastError;
}
500">// Usage
400">const session = 400">await withRetry(() => client.createSession({...}));Retryable Errors
RATE_LIMITED- Always retry after the specified delayINTERNAL_ERROR- Retry with exponential backoffSERVICE_UNAVAILABLE- Retry with exponential backoff
Non-Retryable Errors
- All 400 errors (except rate limits) - Fix the request first
- All 401/403 errors - Authentication/authorization issues
- All 404 errors - Resource doesn't exist