from fastapi import FastAPI, Request from fastapi.responses import JSONResponse app = FastAPI() class MissingIOTDataError(Exception): pass async def missing_data_exception_handler(request: Request, exc: MissingIOTDataError): return JSONResponse( status_code=400, content={"message": "Missing data"} )