Skip to content

Error Handling for API Requests

In the LISA model management API, error handling is designed to ensure robustness and consistent responses when errors occur during the execution of API requests. This section provides a detailed explanation of the error handling mechanisms in place, including the types of errors that are managed, how they are raised, and what kind of responses clients can expect when these errors occur.

Common Errors and Their HTTP Responses

Below is a list of common errors that can occur in the system, along with the HTTP status codes and response structures that are returned to the client.

ModelNotFoundError

  • Description: Raised when a model that is requested for retrieval or deletion is not found in the system.
  • HTTP Status Code: 404 Not Found
  • Response Body:
json
{
    "error": "ModelNotFoundError",
    "message": "The requested model with ID <model_id> could not be found."
}
  • Example Scenario: When a client attempts to fetch details of a model that does not exist in the database, the ModelNotFoundError is raised.

ModelAlreadyExistsError

  • Description: Raised when a request to create a model is made, but the model already exists in the system.
  • HTTP Status Code: 400
  • Response Body:
json
{
    "error": "ModelAlreadyExistsError",
    "message": "A model with the given configuration already exists."
}
  • Example Scenario: A client attempts to create a model with an ID or name that already exists in the database. The system detects the conflict and raises the ModelAlreadyExistsError.

InvalidInputError (Hypothetical Example)

  • Description: Raised when the input provided by the client for creating or updating a model is invalid or does not conform to expected formats.
  • HTTP Status Code: 400 Bad Request
  • Response Body:
json
{
    "error": "InvalidInputError",
    "message": "The input provided is invalid. Please check the required fields and formats."
}
  • Example Scenario: The client submits a malformed JSON body or omits required fields in a model creation request, triggering an InvalidInputError.

Handling Validation Errors

Validation errors are handled across the API via utility functions and model transformation logic. These errors typically occur when user inputs fail validation checks or when required data is missing from a request.

Example Response for Validation Error:

  • HTTP Status Code: 422 Unprocessable Entity
  • Response Body:
json
{
    "error": "ValidationError",
    "message": "The input provided does not meet the required validation criteria."
}