Search Options

Display Count
Sort
Preferred Language
Advanced Search

Results 1 - 10 of 28 for RequestValidationError (0.16 seconds)

The search processing time has exceeded the limit. The displayed results may be partial.

  1. docs_src/custom_request_and_route/tutorial002_an_py310.py

    from collections.abc import Callable
    from typing import Annotated
    
    from fastapi import Body, FastAPI, HTTPException, Request, Response
    from fastapi.exceptions import RequestValidationError
    from fastapi.routing import APIRoute
    
    
    class ValidationErrorLoggingRoute(APIRoute):
        def get_route_handler(self) -> Callable:
            original_route_handler = super().get_route_handler()
    
            async def custom_route_handler(request: Request) -> Response:
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Wed Dec 10 08:55:32 GMT 2025
    - 974 bytes
    - Click Count (0)
  2. docs/en/docs/tutorial/handling-errors.md

    When a request contains invalid data, **FastAPI** internally raises a `RequestValidationError`.
    
    And it also includes a default exception handler for it.
    
    To override it, import the `RequestValidationError` and use it with `@app.exception_handler(RequestValidationError)` to decorate the exception handler.
    
    The exception handler will receive a `Request` and the exception.
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 05 18:13:19 GMT 2026
    - 8.9K bytes
    - Click Count (0)
  3. docs_src/handling_errors/tutorial006_py310.py

    from fastapi import FastAPI, HTTPException
    from fastapi.exception_handlers import (
        http_exception_handler,
        request_validation_exception_handler,
    )
    from fastapi.exceptions import RequestValidationError
    from starlette.exceptions import HTTPException as StarletteHTTPException
    
    app = FastAPI()
    
    
    @app.exception_handler(StarletteHTTPException)
    async def custom_http_exception_handler(request, exc):
        print(f"OMG! An HTTP error!: {repr(exc)}")
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Feb 12 13:19:43 GMT 2026
    - 928 bytes
    - Click Count (0)
  4. docs/ko/docs/how-to/custom-request-and-route.md

    ## 예외 핸들러에서 요청 바디 접근하기 { #accessing-the-request-body-in-an-exception-handler }
    
    /// tip | 팁
    
    같은 문제를 해결하려면 `RequestValidationError`에 대한 커스텀 핸들러에서 `body`를 사용하는 편이 아마 훨씬 더 쉽습니다([오류 처리하기](../tutorial/handling-errors.md#use-the-requestvalidationerror-body)).
    
    하지만 이 예시도 여전히 유효하며, 내부 컴포넌트와 상호작용하는 방법을 보여줍니다.
    
    ///
    
    같은 접근 방식을 사용해 예외 핸들러에서 요청 바디에 접근할 수도 있습니다.
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 14:06:26 GMT 2026
    - 5.2K bytes
    - Click Count (0)
  5. fastapi/exception_handlers.py

    from fastapi.encoders import jsonable_encoder
    from fastapi.exceptions import RequestValidationError, WebSocketRequestValidationError
    from fastapi.utils import is_body_allowed_for_status_code
    from fastapi.websockets import WebSocket
    from starlette.exceptions import HTTPException
    from starlette.requests import Request
    from starlette.responses import JSONResponse, Response
    from starlette.status import WS_1008_POLICY_VIOLATION
    
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Tue Sep 16 17:21:48 GMT 2025
    - 1.2K bytes
    - Click Count (0)
  6. docs/en/docs/how-to/custom-request-and-route.md

    /// tip
    
    To solve this same problem, it's probably a lot easier to use the `body` in a custom handler for `RequestValidationError` ([Handling Errors](../tutorial/handling-errors.md#use-the-requestvalidationerror-body)).
    
    But this example is still valid and it shows how to interact with the internal components.
    
    ///
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 05 18:13:19 GMT 2026
    - 4.4K bytes
    - Click Count (0)
  7. docs/zh-hant/docs/how-to/custom-request-and-route.md

    但由於我們修改了 `GzipRequest.body`,在 **FastAPI** 需要讀取本文時,請求本文會自動解壓縮。
    
    ## 在例外處理器中存取請求本文 { #accessing-the-request-body-in-an-exception-handler }
    
    /// tip
    
    要解決相同問題,使用針對 `RequestValidationError` 的自訂處理器來讀取 `body` 通常更簡單([處理錯誤](../tutorial/handling-errors.md#use-the-requestvalidationerror-body))。
    
    但本範例仍然有效,並示範了如何與內部元件互動。
    
    ///
    
    我們也可以用同樣的方法,在例外處理器中存取請求本文。
    
    我們只需要在 `try`/`except` 區塊中處理請求即可:
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 17:05:38 GMT 2026
    - 4.2K bytes
    - Click Count (0)
  8. docs/ja/docs/how-to/custom-request-and-route.md

    ## 例外ハンドラでのリクエストボディへのアクセス { #accessing-the-request-body-in-an-exception-handler }
    
    /// tip | 豆知識
    
    同じ問題を解決するには、`RequestValidationError` 用のカスタムハンドラで `body` を使う方がずっと簡単でしょう([エラー処理](../tutorial/handling-errors.md#use-the-requestvalidationerror-body))。
    
    ただし、この例も有効で、内部コンポーネントとどのようにやり取りするかを示しています。
    
    ///
    
    同じアプローチを使って、例外ハンドラ内でリクエストボディにアクセスすることもできます。
    
    やることは、`try`/`except` ブロックの中でリクエストを処理するだけです:
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 14:07:17 GMT 2026
    - 5.4K bytes
    - Click Count (0)
  9. fastapi/exceptions.py

            for err in self._errors:
                message += f"  {err}\n"
            message += self._format_endpoint_context()
            return message.rstrip()
    
    
    class RequestValidationError(ValidationException):
        def __init__(
            self,
            errors: Sequence[Any],
            *,
            body: Any = None,
            endpoint_ctx: EndpointContext | None = None,
        ) -> None:
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Wed Feb 11 18:41:21 GMT 2026
    - 7.3K bytes
    - Click Count (0)
  10. docs_src/handling_errors/tutorial005_py310.py

    from fastapi.encoders import jsonable_encoder
    from fastapi.exceptions import RequestValidationError
    from fastapi.responses import JSONResponse
    from pydantic import BaseModel
    
    app = FastAPI()
    
    
    @app.exception_handler(RequestValidationError)
    async def validation_exception_handler(request: Request, exc: RequestValidationError):
        return JSONResponse(
            status_code=422,
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Feb 12 13:19:43 GMT 2026
    - 626 bytes
    - Click Count (0)
Back to Top