Error Handling
Common errors and solutions for wOow Global API
Error Handling
Learn how to handle common API errors and implement proper error handling in your applications.
Overview
The wOow Global API uses standard HTTP status codes and provides detailed error messages to help you identify and resolve issues quickly.
Response Format
All API responses follow a consistent format:
{
"status": true/false,
"message": "Success or error message",
"data": [],
"errors": [],
"response_code": "200"
}HTTP Status Codes
| Status Code | Description | When It Occurs |
|---|---|---|
| 200 | Success | Request completed successfully |
| 201 | Created | Resource created successfully |
| 400 | Bad Request | Invalid request parameters |
| 401 | Unauthorized | Missing or invalid API key |
| 403 | Forbidden | Insufficient permissions |
| 404 | Not Found | Resource not found |
| 429 | Too Many Requests | Rate limit exceeded |
| 500 | Internal Server Error | Server error |
Common Error Types
Authentication Errors
{
"status": false,
"message": "Invalid API key",
"data": [],
"errors": ["Authentication failed"],
"response_code": "401"
}Solutions:
- Verify your API key is correct
- Ensure the API key is included in the Authorization header
- Check if your API key has expired
Validation Errors
{
"status": false,
"message": "Invalid request parameters",
"data": [],
"errors": [
"Invalid package weight",
"Missing required field: sender.name"
],
"response_code": "400"
}Solutions:
- Review the error details for specific field issues
- Ensure all required fields are provided
- Validate data types and formats
Rate Limit Errors
{
"status": false,
"message": "Rate limit exceeded. Try again in 60 seconds.",
"data": [],
"errors": ["Too many requests"],
"response_code": "429"
}Solutions:
- Implement exponential backoff
- Cache responses to reduce API calls
- Monitor your rate limit usage
Resource Not Found
{
"status": false,
"message": "Order not found",
"data": [],
"errors": ["Tracking number WOOW123456789 not found"],
"response_code": "404"
}Solutions:
- Verify the resource ID or tracking number
- Check if the resource has been deleted
- Ensure you're using the correct API endpoint
Error Handling Best Practices
1. Always Check Response Status
const response = await fetch('/api/endpoint');
const data = await response.json();
if (!data.status) {
// Handle error based on response_code
switch (data.response_code) {
case "401":
console.error('Authentication failed:', data.message);
break;
case "429":
console.error('Rate limit exceeded');
break;
default:
console.error('API error:', data.message);
console.error('Errors:', data.errors);
}
}2. Implement Retry Logic
async function makeRequestWithRetry(url, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
const response = await fetch(url);
const data = await response.json();
if (data.response_code === "429") {
const retryAfter = 60; // Default 60 seconds
await new Promise(resolve => setTimeout(resolve, retryAfter * 1000));
continue;
}
return data;
} catch (error) {
if (i === maxRetries - 1) throw error;
await new Promise(resolve => setTimeout(resolve, Math.pow(2, i) * 1000));
}
}
}3. Log Errors for Debugging
function logError(error, context) {
console.error('API Error:', {
status: error.status,
message: error.message,
errors: error.errors,
response_code: error.response_code,
context: context,
timestamp: new Date().toISOString()
});
}Testing Error Scenarios
Test Invalid API Key
curl -X GET "https://api.woowbd.com/categories" \
-H "Authorization: Bearer invalid_key"Test Invalid Request
curl -X POST "https://api.woowbd.com/create-order" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"invalid_field": "invalid_value"
}'Code Examples
JavaScript Error Handling
async function handleApiRequest(url, options = {}) {
try {
const response = await fetch(url, {
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
...options.headers
},
...options
});
const data = await response.json();
if (!data.status) {
throw new Error(`API Error: ${data.message} - ${data.errors.join(', ')}`);
}
return data;
} catch (error) {
console.error('Request failed:', error);
throw error;
}
}Python Error Handling
import requests
def handle_api_request(url, headers=None, data=None):
try:
response = requests.post(
url,
headers=headers,
json=data
)
result = response.json()
if not result.get('status'):
error_message = result.get('message', 'Unknown error')
errors = result.get('errors', [])
raise Exception(f"API Error: {error_message} - {', '.join(errors)}")
return result
except requests.exceptions.RequestException as e:
print(f"Request failed: {e}")
raisePHP Error Handling
function handleApiRequest($url, $headers = [], $data = null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
if ($data) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
}
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($response === false) {
throw new Exception('Request failed');
}
$result = json_decode($response, true);
if (!$result['status']) {
$errorMessage = $result['message'] ?? 'Unknown error';
$errors = $result['errors'] ?? [];
throw new Exception("API Error: $errorMessage - " . implode(', ', $errors));
}
return $result;
}Getting Help
If you encounter errors that aren't covered in this documentation:
- Check the error details for specific information
- Review the API documentation for the endpoint you're using
- Contact support with the error details and your request
- Check our status page for any ongoing issues