Status codes and error handling
RxInferServer uses standard HTTP status codes to indicate the success or failure of API requests. This section describes the responses you can expect from the server.
200 OK
The 200 OK status code indicates that the request was successful.
import RxInferClientOpenAPI.OpenAPI.Clients: Client
import RxInferClientOpenAPI: ServerApi, ping_server, basepath
client = Client(basepath(ServerApi))
response, info = ping_server(ServerApi(client))
info.status
200
response
{
"status": "ok"
}
401 Unauthorized
If you try to access a resource that requires authentication, the server will return a 401 Unauthorized error. This typically happens when you try to access a resource that requires a token, but you haven't provided a valid token.
import RxInferClientOpenAPI.OpenAPI.Clients: Client
import RxInferClientOpenAPI: ServerApi, get_server_info, basepath
client = Client(basepath(ServerApi))
response, info = get_server_info(ServerApi(client))
info.status
401
response
{
"error": "Unauthorized",
"message": "The request requires authentication, generate a token using the /generate-token endpoint or use the development token `dev-token`"
}
For accessing protected resources, you need to provide a valid token. See the Authentication section for more information.
client = Client(basepath(ServerApi); headers = Dict(
"Authorization" => "Bearer $token"
))
404 Not Found
The 404 Not Found error indicates that the resource you're trying to access does not exist.
import RxInferClientOpenAPI: ModelsApi, get_model_instance
response, info = get_model_instance(ModelsApi(client), "non-existent-model")
info.status
404
response
{
"error": "Not Found",
"message": "The requested model instance could not be found"
}
400 Bad Request
The 400 Bad Request error indicates that the request is invalid. This can happen for various reasons, such as invalid JSON payloads, missing required fields, or incorrect parameter values.
import RxInferClientOpenAPI: ModelsApi, CreateModelInstanceRequest, create_model_instance, delete_episode
response, info = create_model_instance(ModelsApi(client), CreateModelInstanceRequest(
model_name = "BetaBernoulli-v1",
description = "Example model for demonstration"
))
# Get the model id from the response
instance_id = response.instance_id
# Attempt to delete the default episode,
# which should result in a 400 Bad Request error
response, info = delete_episode(ModelsApi(client), instance_id, "default")
info.status
400
response
{
"error": "Bad Request",
"message": "Default episode cannot be deleted, wipe data instead"
}