Errors

Error Handling

The API uses conventional HTTP response codes to indicate the success or failure of requests.

HTTP Status Codes

CodeDescription
200Success - Request completed successfully
400Bad Request - Invalid request parameters
401Unauthorized - Invalid or missing API key
404Not Found - Requested resource does not exist
500Internal Server Error - Server error occurred

Error Response Format

All error responses follow a consistent format:

Error Response Structurejson
{
  "success": false,
  "error": "Human-readable error message",
  "code": "ERROR_CODE"
}

Error Codes

CodeDescription
UNAUTHORIZEDInvalid or missing API key
INVALID_PARAMSQuery parameters validation failed
INVALID_IDInvalid UUID format for tariff ID
NOT_FOUNDRequested tariff does not exist
DATABASE_ERRORDatabase query failed
INTERNAL_ERRORUnexpected server error

Example

401 Unauthorized

Missing or invalid API keyjson
{
  "success": false,
  "error": "Unauthorized",
  "code": "UNAUTHORIZED"
}

400 Bad Request

Invalid request parametersjson
{
  "success": false,
  "error": "Invalid query parameters",
  "code": "INVALID_PARAMS"
}

404 Not Found

Resource not foundjson
{
  "success": false,
  "error": "Tariff not found",
  "code": "NOT_FOUND"
}

Best Practices

  • 1.Always check the success field in the response to determine if the request was successful
  • 2.Use the code field for programmatic error handling in your application
  • 3.Display the error message to users for human-readable feedback
  • 4.Implement exponential backoff for retrying failed requests, especially for 5xx errors
Error Handling | Strompreise Schweiz