Skip to main content
Proper error handling is essential for building robust integrations with the Lightyshare API. This guide covers all error types and best practices for handling them.

HTTP Status Codes

The Lightyshare API uses standard HTTP status codes to indicate the success or failure of requests:

Error Response Format

Most error responses follow this format:

Authentication Errors (401)

Missing Token

Invalid Token

Handling Authentication Errors

Validation Errors (400)

Missing Required Fields

Invalid Data Types

Value Constraints

String Length Limits

Handling Validation Errors

Access Control Errors (403)

Resource Access Denied

Handling Access Errors

Not Found Errors (404)

Resource Not Found

Handling Not Found Errors

Rate Limiting Errors (429)

Rate Limit Exceeded

Rate Limit Headers

Handling Rate Limit Errors

Comprehensive Error Handler

Here’s a complete error handling function:

Usage Example

Best Practices

1. Always Handle Errors

Never ignore API errors - always implement proper error handling:

2. Provide User Feedback

Always inform users when errors occur:

3. Implement Retry Logic

For transient errors, implement retry logic:

4. Log Errors Appropriately

Log errors for debugging but don’t expose sensitive information:

5. Graceful Degradation

Design your application to work even when some API calls fail: