- IntroductionGetting startedApi referenceBest practives
Error Handling
On this page
Handling errors from the Swiftia API
The Swiftia API uses standard HTTP status codes to indicate the success or failure of a request. In case of an error, the API returns a JSON object with a consistent format to provide details about the issue.
Error Response Format:**
{
"status": 400, // HTTP status code (e.g., 400, 401, 404, 500)
"message": "Invalid request parameters", // Descriptive error message
"code": "INVALID_INPUT" // (Optional) A specific error code for programmatic handling
}
Common Error Codes:**
400
Bad Request (INVALID_INPUT
): The request parameters are invalid or missing required fields.401
Unauthorized (UNAUTHORIZED
): The request is not authorized (missing or invalid API key).404
Not Found (NOT_FOUND
): The requested resource (e.g., job, render) was not found.429
Too Many Requests (RATE_LIMIT_EXCEEDED
): You have exceeded the rate limit for your API key.500
Internal Server Error (INTERNAL_SERVER_ERROR
): An unexpected error occurred on the server. Please try again later.
Example Error Response:**
{
"status": 400,
"message": "The 'youtubeVideoId' parameter is required.",
"code": "INVALID_INPUT"
}
Handling Errors in Your Code:**
Always check the HTTP status code of the response before processing the data. If the status code indicates an error (4xx or 5xx), parse the JSON response to understand the specific error.
Example (Python):**
import requests
response = requests.get('https://app.swiftia.io/api/jobs/INVALID_JOB_ID')
if response.status_code != 200:
try:
error_data = response.json()
print(f"Error: {error_data['message']} (Code: {error_data.get('code', 'UNKNOWN')})")
except ValueError: # JSON decoding error
print(f"Error: {response.status_code} - {response.text}")
else:
# Process the successful response
data = response.json()
# ...