Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 7 of 7 for StarletteHTTPException (0.11 sec)

  1. docs_src/handling_errors/tutorial004.py

    from fastapi.exceptions import RequestValidationError
    from fastapi.responses import PlainTextResponse
    from starlette.exceptions import HTTPException as StarletteHTTPException
    
    app = FastAPI()
    
    
    @app.exception_handler(StarletteHTTPException)
    async def http_exception_handler(request, exc):
        return PlainTextResponse(str(exc.detail), status_code=exc.status_code)
    
    
    @app.exception_handler(RequestValidationError)
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Thu Mar 26 19:09:53 UTC 2020
    - 762 bytes
    - Viewed (0)
  2. docs_src/handling_errors/tutorial006.py

        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)}")
        return await http_exception_handler(request, exc)
    
    
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sun Aug 09 11:10:33 UTC 2020
    - 928 bytes
    - Viewed (0)
  3. fastapi/exceptions.py

    from pydantic import BaseModel, create_model
    from starlette.exceptions import HTTPException as StarletteHTTPException
    from starlette.exceptions import WebSocketException as StarletteWebSocketException
    from typing_extensions import Annotated, Doc
    
    
    class HTTPException(StarletteHTTPException):
        """
        An HTTP exception you can raise in your own code to show errors to the client.
    
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Tue Apr 02 02:48:51 UTC 2024
    - 4.9K bytes
    - Viewed (0)
  4. tests/test_starlette_exception.py

    from fastapi import FastAPI, HTTPException
    from fastapi.testclient import TestClient
    from starlette.exceptions import HTTPException as StarletteHTTPException
    
    app = FastAPI()
    
    items = {"foo": "The Foo Wrestlers"}
    
    
    @app.get("/items/{item_id}")
    async def read_item(item_id: str):
        if item_id not in items:
            raise HTTPException(
                status_code=404,
                detail="Item not found",
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Fri Jun 30 18:25:16 UTC 2023
    - 7.4K bytes
    - Viewed (0)
  5. docs/em/docs/tutorial/handling-errors.md

    👉 🌌, 🚥 🙆 🍕 💃 🔗 📟, ⚖️ 💃 ↔ ⚖️ 🔌 -, 🤚 💃 `HTTPException`, 👆 🐕‍🦺 🔜 💪 ✊ & 🍵 ⚫️.
    
    👉 🖼, 💪 ✔️ 👯‍♂️ `HTTPException`Ⓜ 🎏 📟, 💃 ⚠ 📁 `StarletteHTTPException`:
    
    ```Python
    from starlette.exceptions import HTTPException as StarletteHTTPException
    ```
    
    ### 🏤-⚙️ **FastAPI**'Ⓜ ⚠ 🐕‍🦺
    
    🚥 👆 💚 ⚙️ ⚠ ⤴️ ⏮️ 🎏 🔢 ⚠ 🐕‍🦺 ⚪️➡️ **FastAPI**, 👆 💪 🗄 & 🏤-⚙️ 🔢 ⚠ 🐕‍🦺 ⚪️➡️ `fastapi.exception_handlers`:
    
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sun Oct 06 20:36:54 UTC 2024
    - 8.3K bytes
    - Viewed (0)
  6. docs/en/docs/tutorial/handling-errors.md

    In this example, to be able to have both `HTTPException`s in the same code, Starlette's exceptions is renamed to `StarletteHTTPException`:
    
    ```Python
    from starlette.exceptions import HTTPException as StarletteHTTPException
    ```
    
    ### Reuse **FastAPI**'s exception handlers
    
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sun Oct 06 20:36:54 UTC 2024
    - 9.1K bytes
    - Viewed (0)
  7. docs/zh/docs/tutorial/handling-errors.md

    这样做是为了,当 Starlette 的内部代码、扩展或插件触发 Starlette `HTTPException` 时,处理程序能够捕获、并处理此异常。
    
    注意,本例代码中同时使用了这两个 `HTTPException`,此时,要把 Starlette 的 `HTTPException` 命名为 `StarletteHTTPException`:
    
    ```Python
    from starlette.exceptions import HTTPException as StarletteHTTPException
    
    ```
    
    ### 复用 **FastAPI** 异常处理器
    
    FastAPI 支持先对异常进行某些处理,然后再使用 **FastAPI** 中处理该异常的默认异常处理器。
    
    从 `fastapi.exception_handlers` 中导入要复用的默认异常处理器:
    
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sun Oct 06 20:36:54 UTC 2024
    - 8.4K bytes
    - Viewed (0)
Back to top