Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 47 for handling (0.2 sec)

  1. docs/zh/docs/tutorial/handling-errors.md

    但对于某些高级应用场景,还是需要添加自定义响应头:
    
    ```Python hl_lines="14"
    {!../../../docs_src/handling_errors/tutorial002.py!}
    
    ```
    
    ## 安装自定义异常处理器
    
    添加自定义处理器,要使用 [Starlette 的异常工具](https://www.starlette.io/exceptions/)。
    
    假设要触发的自定义异常叫作 `UnicornException`。
    
    且需要 FastAPI 实现全局处理该异常。
    
    此时,可以用 `@app.exception_handler()` 添加自定义异常控制器:
    
    ```Python hl_lines="5-7  13-18  24"
    {!../../../docs_src/handling_errors/tutorial003.py!}
    
    ```
    
    Plain Text
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Fri Mar 22 01:42:11 GMT 2024
    - 8.4K bytes
    - Viewed (0)
  2. docs/em/docs/tutorial/handling-errors.md

    💭 🌐 👈 **"4️⃣0️⃣4️⃣ 🚫 🔎"** ❌ (& 🤣) ❓
    
    ## ⚙️ `HTTPException`
    
    📨 🇺🇸🔍 📨 ⏮️ ❌ 👩‍💻 👆 ⚙️ `HTTPException`.
    
    ### 🗄 `HTTPException`
    
    ```Python hl_lines="1"
    {!../../../docs_src/handling_errors/tutorial001.py!}
    ```
    
    ### 🤚 `HTTPException` 👆 📟
    
    `HTTPException` 😐 🐍 ⚠ ⏮️ 🌖 📊 🔗 🔗.
    
    ↩️ ⚫️ 🐍 ⚠, 👆 🚫 `return` ⚫️, 👆 `raise` ⚫️.
    
    Plain Text
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Fri Mar 22 01:42:11 GMT 2024
    - 8.3K bytes
    - Viewed (0)
  3. docs/ja/docs/tutorial/handling-errors.md

    **"404 Not Found"** のエラー(およびジョーク)を覚えていますか?
    
    ## `HTTPException`の使用
    
    HTTPレスポンスをエラーでクライアントに返すには、`HTTPException`を使用します。
    
    ### `HTTPException`のインポート
    
    ```Python hl_lines="1"
    {!../../../docs_src/handling_errors/tutorial001.py!}
    ```
    
    ### コード内での`HTTPException`の発生
    
    `HTTPException`は通常のPythonの例外であり、APIに関連するデータを追加したものです。
    
    Pythonの例外なので、`return`ではなく、`raise`です。
    
    Plain Text
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Fri Mar 22 01:42:11 GMT 2024
    - 11.8K bytes
    - Viewed (0)
  4. docs/en/docs/tutorial/handling-errors.md

    # Handling Errors
    
    There are many situations in which you need to notify an error to a client that is using your API.
    
    This client could be a browser with a frontend, a code from someone else, an IoT device, etc.
    
    You could need to tell the client that:
    
    * The client doesn't have enough privileges for that operation.
    * The client doesn't have access to that resource.
    * The item the client was trying to access doesn't exist.
    * etc.
    
    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)
  5. docs/pt/docs/tutorial/handling-errors.md

    ## Use o `HTTPException`
    
    Para retornar ao cliente *responses* HTTP com erros, use o `HTTPException`.
    
    ### Import `HTTPException`
    
    ```Python hl_lines="1"
    {!../../../docs_src/handling_errors/tutorial001.py!}
    ```
    
    ### Lance o `HTTPException` no seu código.
    
    `HTTPException`, ao fundo, nada mais é do que a conjunção entre uma exceção comum do Python e informações adicionais relevantes para APIs.
    
    Plain Text
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Fri Mar 22 01:42:11 GMT 2024
    - 10K bytes
    - Viewed (0)
  6. docs/ru/docs/tutorial/handling-errors.md

    ## Использование `HTTPException`
    
    Для возврата клиенту HTTP-ответов с ошибками используется `HTTPException`.
    
    ### Импортируйте `HTTPException`
    
    ```Python hl_lines="1"
    {!../../../docs_src/handling_errors/tutorial001.py!}
    ```
    
    ### Вызовите `HTTPException` в своем коде
    
    `HTTPException` - это обычное исключение Python с дополнительными данными, актуальными для API.
    
    Plain Text
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Fri Mar 22 01:42:11 GMT 2024
    - 14.5K bytes
    - Viewed (0)
  7. docs/de/docs/tutorial/handling-errors.md

    ## `HTTPException` verwenden
    
    Um HTTP-Responses mit Fehlern zum Client zurückzugeben, verwenden Sie `HTTPException`.
    
    ### `HTTPException` importieren
    
    ```Python hl_lines="1"
    {!../../../docs_src/handling_errors/tutorial001.py!}
    ```
    
    ### Eine `HTTPException` in Ihrem Code auslösen
    
    Plain Text
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Sat Mar 30 20:28:29 GMT 2024
    - 10.6K bytes
    - Viewed (0)
  8. docs/en/docs/tutorial/static-files.md

    ### What is "Mounting"
    
    "Mounting" means adding a complete "independent" application in a specific path, that then takes care of handling all the sub-paths.
    
    This is different from using an `APIRouter` as a mounted application is completely independent. The OpenAPI and docs from your main application won't include anything from the mounted application, etc.
    
    Plain Text
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Thu Jan 11 19:56:09 GMT 2024
    - 1.6K bytes
    - Viewed (0)
  9. tests/test_tutorial/test_handling_errors/test_tutorial005.py

    from dirty_equals import IsDict
    from fastapi.testclient import TestClient
    
    from docs_src.handling_errors.tutorial005 import app
    
    client = TestClient(app)
    
    
    def test_post_validation_error():
        response = client.post("/items/", json={"title": "towel", "size": "XL"})
        assert response.status_code == 422, response.text
        assert response.json() == IsDict(
            {
                "detail": [
                    {
    Python
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Thu Apr 18 19:40:57 GMT 2024
    - 4.3K bytes
    - Viewed (0)
  10. docs/zh/docs/advanced/custom-request-and-route.md

    之后,所有处理逻辑都一样。
    
    但因为改变了 `GzipRequest.body`,**FastAPI** 加载请求体时会自动解压。
    
    ## 在异常处理器中访问请求体
    
    !!! tip "提示"
    
        为了解决同样的问题,在 `RequestValidationError` 的自定义处理器使用 `body`  ([处理错误](../tutorial/handling-errors.md#use-the-requestvalidationerror-body){.internal-link target=_blank})可能会更容易。
    
        但本例仍然可行,而且本例展示了如何与内部组件进行交互。
    
    同样也可以在异常处理器中访问请求体。
    
    此时要做的只是处理 `try`/`except` 中的请求:
    
    ```Python hl_lines="13  15"
    Plain Text
    - Registered: Sun Mar 31 07:19:09 GMT 2024
    - Last Modified: Sat Mar 30 22:45:40 GMT 2024
    - 3.8K bytes
    - Viewed (0)
Back to top