Hello, I have a question about exception handling....
# ask-for-help
k
Hello, I have a question about exception handling. In FastAPI, you can define custom exceptions and add event handlers to
app
to handle them with specific response messages. Even for Pydantic validation exceptions, you can add event handlers to customize responses. Is there a similar feature in BentoML services where you can register event handlers in the service to handle exceptions this way? ============================================================================ from fastapi import FastAPI, HTTPException, Request from fastapi.responses import JSONResponse class CustomException(HTTPException): def __init__(self, detail: str = "Custom Request failed"): super().__init__(status_code=401, detail=detail) app = FastAPI() @app.exception_handler(CustomException) async def auth_exception_handler(request: Request, exc: CustomException): return JSONResponse( status_code=exc.status_code, content={"message": exc.detail}, ) @app.get("/protected-route") async def protected_route(token: str): if token != "valid-token": raise CustomException() return {"message": "You have access to this route"} ===============================================================================