mirror of
https://github.com/fastapi/fastapi.git
synced 2026-02-06 12:21:13 -05:00
* 🔥 Remove support for Pydantic < 1.0 * 🔥 Remove deprecated skip_defaults from jsonable_encoder and set default for exclude to None, as in Pydantic * ♻️ Set default of response_model_exclude=None as in Pydantic * ⬆️ Require Pydantic >=1.0.0 in requirements
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
from typing import Any, Dict, Optional, Sequence
|
|
|
|
from pydantic import ValidationError, create_model
|
|
from pydantic.error_wrappers import ErrorList
|
|
from starlette.exceptions import HTTPException as StarletteHTTPException
|
|
|
|
|
|
class HTTPException(StarletteHTTPException):
|
|
def __init__(
|
|
self,
|
|
status_code: int,
|
|
detail: Any = None,
|
|
headers: Optional[Dict[str, Any]] = None,
|
|
) -> None:
|
|
super().__init__(status_code=status_code, detail=detail)
|
|
self.headers = headers
|
|
|
|
|
|
RequestErrorModel = create_model("Request")
|
|
WebSocketErrorModel = create_model("WebSocket")
|
|
|
|
|
|
class FastAPIError(RuntimeError):
|
|
"""
|
|
A generic, FastAPI-specific error.
|
|
"""
|
|
|
|
|
|
class RequestValidationError(ValidationError):
|
|
def __init__(self, errors: Sequence[ErrorList], *, body: Any = None) -> None:
|
|
self.body = body
|
|
super().__init__(errors, RequestErrorModel)
|
|
|
|
|
|
class WebSocketRequestValidationError(ValidationError):
|
|
def __init__(self, errors: Sequence[ErrorList]) -> None:
|
|
super().__init__(errors, WebSocketErrorModel)
|