Documentation / Errors

Error Handling

How to handle API errors

When an error occurs, the API returns an appropriate HTTP status code and a JSON error response.

HTTP Status Codes

  • 400 Bad Request - Invalid request parameters
  • 401 Unauthorized - Missing or invalid authentication
  • 403 Forbidden - Insufficient permissions
  • 404 Not Found - Resource not found
  • 405 Method Not Allowed - HTTP method not supported
  • 500 Internal Server Error - Server error

Error Response Format

Error responses include:

  • Message - Human-readable error description
  • ErrorCode - Numeric error code for programmatic handling
  • Details - Additional error details (may be null)

Common Errors

401 Unauthorized

Your access token is missing, expired, or invalid. Request a new token.

400 Bad Request

Check the error message for specific validation failures. Common causes:

  • Missing required fields
  • Invalid field values
  • Incorrect data types
  • Duplicate resource names

Best Practices

  • Always check HTTP status codes
  • Log error messages for debugging
  • Implement retry logic for 5xx errors
  • Handle 401 errors by refreshing the token

Code Examples

# Error Response Example
{
  "Message": "Specified name is taken by an existing snippet",
  "ErrorCode": 11001,
  "Details": null
}

# Handling Errors (JavaScript)
try {
  const response = await fetch(url, options);
  if (!response.ok) {
    const error = await response.json();
    console.error('API Error:', error.Message);
    throw new Error(error.Message);
  }
  return await response.json();
} catch (error) {
  // Handle network or parsing errors
  console.error('Request failed:', error);
}