ViralVelocity-api / app /core /exceptions.py
Rolaficus's picture
tried linitng with black
c36cbde
Raw History Blame Contribute Delete
804 Bytes
from fastapi import Request
from fastapi.responses import JSONResponse
class ModelError(Exception):
"""Base exception for model-related errors"""
pass
class ModelNotLoadedError(ModelError):
"""Raised when trying to predict with a model that isn't loaded"""
pass
class PredictionError(ModelError):
"""Raised when the inference step fails"""
pass
async def model_exception_handler(request: Request, exc: ModelError):
"""
Global exception handler for the FastAPI app.
Add this to app.py: app.add_exception_handler(ModelError, model_exception_handler)
"""
return JSONResponse(
status_code=500,
content={
"error": exc.__class__.__name__,
"message": str(exc),
"path": request.url.path,
},
)