from fastapi.responses import JSONResponse def handle_exception(e: Exception): """Helper function to handle exceptions in a consistent way.""" return JSONResponse( status_code=500, content={ "status": "exception error", "message": "An unexpected error occurred", "details": str(e), }, ) def handle_error(e, message): return JSONResponse( status_code=500, content={"status": "error", "error": f"error in {message}", "details": str(e)}, ) def not_found_error(message): return JSONResponse( status_code=404, content={"status": "error", "error": "Not Found", "details": message}, ) def no_entries_found(message): return JSONResponse( status_code=404, content={"status": "error", "error": "No Entries Found", "details": message}, )