LiteAPI uses standard HTTP status codes to indicate the success or failure of an API request.

Here are the common status codes and their meanings:

  • 200 OK: The request was successful.
  • 400 Bad Request: The request was invalid or cannot be served.
  • 401 Unauthorized: Authentication failed or API key is missing.
  • 403 Forbidden: You do not have access to the requested resource.
  • 404 Not Found: The requested resource could not be found.
  • 500 Internal Server Error: An error occurred on the server.

Example Error Response:

{
  "error": {
    "code": 400,
    "message": "Invalid city name."
  }
}

Handling Errors in Code:

Here's an example JavaScript script to handle errors when using our API endpoints.

fetch('https://api.liteapi.travel/v3.0/data/hotels?city=InvalidCity', {
    headers: {
        'X-API-Key': 'YOUR_API_KEY'
    }
})
.then(response => {
    if (!response.ok) {
        return response.json().then(error => Promise.reject(error));
    }
    return response.json();
})
.catch(error => {
    console.error('Error:', error);
});