Error Handling
The MagicSlides API uses conventional HTTP response codes and provides detailed error messages to indicate the success or failure of requests.
HTTP Status Codes
Status Code
Description
200 OK
The request was successful
400 Bad Request
The request was invalid or missing required parameters
401 Unauthorized
Invalid or missing access ID
403 Forbidden
The access ID is valid but lacks permission
429 Too Many Requests
Rate limit exceeded
500 Internal Server Error
An error occurred on our servers
Error Response Format
When an error occurs, the API returns a JSON response with the following structure:
{
"success": false,
"error": "A human-readable error message",
"code": "ERROR_CODE",
"details": {
// Additional error details if available
}
}
Common Error Codes
AUTH_ERROR
Authentication-related errors
INVALID_PARAMS
Invalid or missing request parameters
RATE_LIMIT_ERROR
Rate limit exceeded
PROCESSING_ERROR
Error during presentation generation
YOUTUBE_ERROR
Error accessing or processing YouTube video
SERVER_ERROR
Internal server error
Error Examples
Invalid Parameters
{
"success": false,
"error": "Missing required parameter: topic",
"code": "INVALID_PARAMS",
"details": {
"missing": ["topic"]
}
}
Authentication Error
{
"success": false,
"error": "Invalid access ID provided",
"code": "AUTH_ERROR"
}
Rate Limit Error
{
"success": false,
"error": "Rate limit exceeded",
"code": "RATE_LIMIT_ERROR",
"reset_at": 1678945200
}
Error Handling Best Practices
- Always check the success field in the response
- Implement proper error handling for all API calls
- Log error details for debugging purposes
- Implement retries with exponential backoff for recoverable errors
- Display user-friendly error messages in your application
Example Implementation
import axios, { AxiosError } from 'axios';
interface ApiError {
success: false;
error: string;
code: string;
details?: Record<string, any>;
}
async function handleApiRequest() {
try {
const response = await axios.post(
'https://magicslides-tools-api.onrender.com/public/api/ppt_from_topic',
{
topic: 'AI in Healthcare',
email: 'user@example.com',
accessId: 'your-access-id'
}
);
return response.data;
} catch (error) {
if (error instanceof AxiosError) {
const apiError = error.response?.data as ApiError;
switch (apiError.code) {
case 'AUTH_ERROR':
console.error('Authentication failed:', apiError.error);
// Handle auth error (e.g., redirect to login)
break;
case 'RATE_LIMIT_ERROR':
console.error('Rate limit exceeded:', apiError.error);
// Implement retry logic
break;
case 'INVALID_PARAMS':
console.error('Invalid parameters:', apiError.details);
// Handle validation errors
break;
default:
console.error('API error:', apiError.error);
// Handle other errors
}
}
throw error;
}
}