Error Handling

Learn how to handle API errors gracefully.

Error Response Format

All error responses follow this format:

{
  "success": false,
  "message": "Error description",
  "errors": [],
  "timestamp": 1234567890
}

HTTP Status Codes

Code Meaning Common Causes
400 Bad Request Missing required parameters, invalid data format
401 Unauthorized Missing or invalid API key
403 Forbidden Valid API key but insufficient permissions
404 Not Found Resource doesn't exist
405 Method Not Allowed Wrong HTTP method for endpoint
429 Too Many Requests Rate limit exceeded
500 Internal Server Error Server-side error

Error Handling Example

fetch('https://api.tksmods.in/apps', {
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY'
  }
})
.then(response => {
  if (!response.ok) {
    throw new Error(`HTTP ${response.status}: ${response.statusText}`);
  }
  return response.json();
})
.then(data => {
  if (!data.success) {
    console.error('API Error:', data.message);
    return;
  }
  // Handle success
  console.log(data.data);
})
.catch(error => {
  console.error('Request failed:', error);
});