Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 89 for handlers (0.26 sec)

  1. fastapi/exception_handlers.py

        )
    
    
    async def request_validation_exception_handler(
        request: Request, exc: RequestValidationError
    ) -> JSONResponse:
        return JSONResponse(
            status_code=HTTP_422_UNPROCESSABLE_ENTITY,
            content={"detail": jsonable_encoder(exc.errors())},
        )
    
    
    async def websocket_request_validation_exception_handler(
        websocket: WebSocket, exc: WebSocketRequestValidationError
    ) -> None:
    Python
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Sun Jun 11 19:08:14 GMT 2023
    - 1.3K bytes
    - Viewed (0)
  2. tests/test_exception_handlers.py

    app = FastAPI(
        exception_handlers={
            HTTPException: http_exception_handler,
            RequestValidationError: request_validation_exception_handler,
            Exception: server_error_exception_handler,
        }
    )
    
    client = TestClient(app)
    
    
    @app.get("/http-exception")
    def route_with_http_exception():
        raise HTTPException(status_code=400)
    
    
    @app.get("/request-validation/{param}/")
    Python
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Thu Feb 17 12:40:12 GMT 2022
    - 1.9K bytes
    - Viewed (0)
  3. docs/en/docs/tutorial/handling-errors.md

    ## Override the default exception handlers
    
    **FastAPI** has some default exception handlers.
    
    These handlers are in charge of returning the default JSON responses when you `raise` an `HTTPException` and when the request has invalid data.
    
    You can override these exception handlers with your own.
    
    ### Override request validation exceptions
    
    Plain Text
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Fri Mar 22 01:42:11 GMT 2024
    - 9.1K bytes
    - Viewed (0)
  4. docs/en/docs/advanced/events.md

    {!../../../docs_src/events/tutorial001.py!}
    ```
    
    In this case, the `startup` event handler function will initialize the items "database" (just a `dict`) with some values.
    
    You can add more than one event handler function.
    
    And your application won't start receiving requests until all the `startup` event handlers have completed.
    
    ### `shutdown` event
    
    Plain Text
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Thu Apr 18 19:53:19 GMT 2024
    - 7.8K bytes
    - Viewed (0)
  5. docs/en/docs/tutorial/dependencies/dependencies-with-yield.md

    This was changed in version 0.110.0 to fix unhandled memory consumption from forwarded exceptions without a handler (internal server errors), and to make it consistent with the behavior of regular Python code.
    
    Plain Text
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Sat Feb 24 23:06:37 GMT 2024
    - 14.1K bytes
    - Viewed (0)
  6. docs/ru/docs/tutorial/dependencies/dependencies-with-yield.md

        opt raise
            dep -->> handler: Raise HTTPException
            handler -->> client: HTTP error response
            dep -->> dep: Raise other exception
        end
        dep ->> operation: Run dependency, e.g. DB session
        opt raise
            operation -->> dep: Raise HTTPException
            dep -->> handler: Auto forward exception
            handler -->> client: HTTP error response
    Plain Text
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Tue Apr 02 04:21:06 GMT 2024
    - 19.6K bytes
    - Viewed (0)
  7. docs/zh/docs/tutorial/dependencies/dependencies-with-yield.md

    !!! tip
    
        在`yield`之前仍然可以引发包括`HTTPException`在内的异常,但在`yield`之后则不行。
    
    执行的顺序大致如下图所示。时间从上到下流动。每列都是相互交互或执行代码的其中一部分。
    
    ```mermaid
    sequenceDiagram
    
    participant client as Client
    participant handler as Exception handler
    participant dep as Dep with yield
    participant operation as Path Operation
    Plain Text
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Thu Apr 18 19:53:19 GMT 2024
    - 10.3K bytes
    - Viewed (0)
  8. tests/test_router_events.py

        sub_router_shutdown: bool = False
    
    
    @pytest.fixture
    def state() -> State:
        return State()
    
    
    @pytest.mark.filterwarnings(
        r"ignore:\s*on_event is deprecated, use lifespan event handlers instead.*:DeprecationWarning"
    )
    def test_router_events(state: State) -> None:
        app = FastAPI()
    
        @app.get("/")
        def main() -> Dict[str, str]:
            return {"message": "Hello World"}
    
    Python
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Wed Oct 18 12:36:40 GMT 2023
    - 3.2K bytes
    - Viewed (0)
  9. fastapi/applications.py

            )
            self.exception_handlers: Dict[
                Any, Callable[[Request, Any], Union[Response, Awaitable[Response]]]
            ] = {} if exception_handlers is None else dict(exception_handlers)
            self.exception_handlers.setdefault(HTTPException, http_exception_handler)
            self.exception_handlers.setdefault(
                RequestValidationError, request_validation_exception_handler
            )
    Python
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Tue Apr 02 02:48:51 GMT 2024
    - 172.2K bytes
    - Viewed (0)
  10. docs_src/handling_errors/tutorial006.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)}")
    Python
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Sun Aug 09 11:10:33 GMT 2020
    - 928 bytes
    - Viewed (0)
Back to top