Skip to content

exception_handlers

OPTIMADE_EXCEPTIONS: Tuple[Exception, Callable[[starlette.requests.Request, Exception], starlette.responses.JSONResponse]]

A tuple of all pairs of exceptions and handler functions that allow for appropriate responses to be returned in certain scenarios according to the OPTIMADE specification.

To use these in FastAPI app code:

from fastapi import FastAPI
app = FastAPI()
for exception, handler in OPTIMADE_EXCEPTIONS:
    app.add_exception_handler(exception, handler)