Skip to content

Error Handling

The LuxMart API uses standard HTTP status codes and returns error messages in JSON format.

HTTP Status Codes

Code Meaning Description
200 OK Request successful
400 Bad Request Invalid request parameters or validation error
401 Unauthorized Missing or invalid authentication token
403 Forbidden Insufficient permissions for the requested resource
404 Not Found Resource not found
500 Internal Server Error Server error occurred

Error Response Format

Errors are returned in the following format:

{
  "error": "Error message description"
}

Or for validation errors:

{
  "message": "Validation error message"
}

Common Error Scenarios

Validation Errors

Request:

{
  "email": "invalid-email",
  "password": "123"
}

Response (400):

{
  "error": "Is not correct email format!"
}

Authentication Errors

Request:

GET /v1/accounts/user/site/
# Missing Authorization header

Response (401):

{
  "error": "Missing token on header!"
}

Not Found Errors

Request:

GET /v1/products/store/get-by/?id=99999

Response (404):

{
  "error": "Product not found"
}

Permission Errors

Request:

# User trying to access admin-only endpoint
GET /v1/contacts/admin/

Response (403):

{
  "error": "Access denied!"
}

Error Handling Best Practices

  1. Always check status codes before processing response data
  2. Handle 401 errors by prompting user to re-authenticate
  3. Handle 403 errors by showing appropriate permission messages
  4. Log 500 errors and report to support
  5. Validate input client-side to reduce 400 errors