Error Handling

Learn how to handle errors gracefully in your URI Social SDK integration.

HTTP Status Codes

200

Success

OK - Request succeeded

201

Success

Created - Resource created successfully

400

Client Error

Bad Request - Invalid parameters

401

Client Error

Unauthorized - Invalid or missing API key

403

Client Error

Forbidden - Insufficient permissions

404

Client Error

Not Found - Resource not found

402

Client Error

Payment Required - Insufficient generation credits

429

Client Error

Too Many Requests - Rate limit exceeded

500

Server 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