Error Handling
Learn how to handle errors gracefully in your URI Social SDK integration.
HTTP Status Codes
200Success
OK - Request succeeded
201Success
Created - Resource created successfully
400Client Error
Bad Request - Invalid parameters
401Client Error
Unauthorized - Invalid or missing API key
403Client Error
Forbidden - Insufficient permissions
404Client Error
Not Found - Resource not found
402Client Error
Payment Required - Insufficient generation credits
429Client Error
Too Many Requests - Rate limit exceeded
500Server Error
Internal Server Error - Something went wrong
Error Response Format
{
"detail": "Insufficient credits. Please upgrade your plan."
}Handling Errors
import { AuthenticationError, RateLimitError, InsufficientCreditsError } from '@urisocial/sdk';
try {
const content = await client.content.generate({
seedContent: 'Hello World',
platforms: ['instagram']
});
console.log('Success:', content);
} catch (error) {
if (error instanceof AuthenticationError) {
console.error('Authentication failed. Check your API key.');
} else if (error instanceof RateLimitError) {
console.error(`Rate limit exceeded. Retry after ${error.retryAfter}ms`);
} else if (error instanceof InsufficientCreditsError) {
console.error(`Out of credits (${error.creditsRemaining} remaining). ${error.upgradeUrl}`);
} else if (error.statusCode && error.statusCode >= 500) {
console.error('Server error. Please try again.');
} else {
console.error('Error:', error.message);
}
}Error Handling Best Practices
- • Always wrap API calls in try-catch blocks
- • Log errors for debugging purposes
- • Provide user-friendly error messages
- • Implement retry logic for transient errors
- • Monitor error rates in production
Need Help?
If you're experiencing persistent errors, contact our support team for assistance.
Contact Support