Spaces:
Paused
Paused
Download api/core/exceptions.py from mrqadeer/email-classifier: direct link, hf CLI and curl.
- Browser
- Download file 1.65 kB
-
https://huggingface.co/spaces/mrqadeer/email-classifier/resolve/main/api/core/exceptions.py
- Command line
-
hf download hf://spaces/mrqadeer/email-classifier/api/core/exceptions.py
-
curl -L -o exceptions.py https://huggingface.co/spaces/mrqadeer/email-classifier/resolve/main/api/core/exceptions.py
1.65 kB
| from fastapi import HTTPException | |
| from typing import Any, Dict, Optional | |
| class CustomException(HTTPException): | |
| """Base custom exception class""" | |
| def __init__( | |
| self, | |
| status_code: int, | |
| detail: str, | |
| error_code: str = "ERROR", | |
| headers: Optional[Dict[str, Any]] = None | |
| ): | |
| self.status_code = status_code | |
| self.detail = detail | |
| self.error_code = error_code | |
| self.headers = headers | |
| class ModelLoadException(CustomException): | |
| """Raised when model loading fails""" | |
| def __init__(self, detail: str = "Failed to load model"): | |
| super().__init__( | |
| status_code=500, | |
| detail=detail, | |
| error_code="MODEL_LOAD_ERROR" | |
| ) | |
| class PredictionException(CustomException): | |
| """Raised when prediction fails""" | |
| def __init__(self, detail: str = "Failed to make prediction"): | |
| super().__init__( | |
| status_code=500, | |
| detail=detail, | |
| error_code="PREDICTION_ERROR" | |
| ) | |
| class RateLimitException(CustomException): | |
| """Raised when rate limit is exceeded""" | |
| def __init__(self, detail: str = "Rate limit exceeded"): | |
| super().__init__( | |
| status_code=429, | |
| detail=detail, | |
| error_code="RATE_LIMIT_EXCEEDED", | |
| headers={"Retry-After": "3600"} | |
| ) | |
| class ValidationException(CustomException): | |
| """Raised when input validation fails""" | |
| def __init__(self, detail: str = "Validation error"): | |
| super().__init__( | |
| status_code=422, | |
| detail=detail, | |
| error_code="VALIDATION_ERROR" | |
| ) | |