Spaces:
Sleeping
Sleeping
Download app/exceptions.py from nix3s/futurisys_ml_api: direct link, hf CLI and curl.
- Browser
- Download file 903 Bytes
-
https://huggingface.co/spaces/nix3s/futurisys_ml_api/resolve/main/app/exceptions.py
- Command line
-
hf download hf://spaces/nix3s/futurisys_ml_api/app/exceptions.py
-
curl -L -o exceptions.py https://huggingface.co/spaces/nix3s/futurisys_ml_api/resolve/main/app/exceptions.py
903 Bytes
| from fastapi import FastAPI, Request | |
| from fastapi.exceptions import RequestValidationError | |
| from fastapi.responses import JSONResponse | |
| app = FastAPI() | |
| async def validation_exception_handler(request: Request, exc: RequestValidationError): | |
| errors = [] | |
| for error in exc.errors(): | |
| field_name = error["loc"][-1] | |
| if error["type"] == "missing": | |
| # Champ manquant | |
| errors.append(f"Feature manquante : {field_name}") | |
| elif error["type"].startswith("type_error") or error["type"].startswith("value_error"): | |
| # Type incorrect | |
| errors.append(f"Type incorrect pour {field_name} : {error['msg']}") | |
| else: | |
| # Autres erreurs | |
| errors.append(f"{field_name} : {error['msg']}") | |
| return JSONResponse( | |
| status_code=422, | |
| content={"detail": errors}, | |
| ) |