Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 9 of 9 for UnicornException (0.23 sec)

  1. docs_src/handling_errors/tutorial003.py

    from fastapi import FastAPI, Request
    from fastapi.responses import JSONResponse
    
    
    class UnicornException(Exception):
        def __init__(self, name: str):
            self.name = name
    
    
    app = FastAPI()
    
    
    @app.exception_handler(UnicornException)
    async def unicorn_exception_handler(request: Request, exc: UnicornException):
        return JSONResponse(
            status_code=418,
    Python
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Thu Mar 26 19:09:53 GMT 2020
    - 626 bytes
    - Viewed (0)
  2. docs/ru/docs/tutorial/handling-errors.md

    Допустим, у вас есть пользовательское исключение `UnicornException`, которое вы (или используемая вами библиотека) можете `вызвать`.
    
    И вы хотите обрабатывать это исключение глобально с помощью FastAPI.
    
    Можно добавить собственный обработчик исключений с помощью `@app.exception_handler()`:
    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)
  3. docs/pt/docs/tutorial/handling-errors.md

    Digamos que você tenha uma exceção customizada `UnicornException` que você (ou uma biblioteca que você use) precise lançar (`raise`).
    
    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)
  4. docs/en/docs/tutorial/handling-errors.md

    You can add custom exception handlers with <a href="https://www.starlette.io/exceptions/" class="external-link" target="_blank">the same exception utilities from Starlette</a>.
    
    Let's say you have a custom exception `UnicornException` that you (or a library you use) might `raise`.
    
    And you want to handle this exception globally with FastAPI.
    
    You could add a custom exception handler with `@app.exception_handler()`:
    
    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/de/docs/tutorial/handling-errors.md

    Nehmen wir an, Sie haben eine benutzerdefinierte Exception `UnicornException`, die Sie (oder eine Bibliothek, die Sie verwenden) `raise`n könnten.
    
    Und Sie möchten diese Exception global mit FastAPI handhaben.
    
    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)
  6. docs/zh/docs/tutorial/handling-errors.md

    添加自定义处理器,要使用 [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!}
    
    ```
    
    请求 `/unicorns/yolo` 时,路径操作会触发 `UnicornException`。
    
    但该异常将会被 `unicorn_exception_handler` 处理。
    
    接收到的错误信息清晰明了,HTTP 状态码为 `418`,JSON 内容如下:
    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)
  7. docs/em/docs/tutorial/handling-errors.md

    ➡️ 💬 👆 ✔️ 🛃 ⚠ `UnicornException` 👈 👆 (⚖️ 🗃 👆 ⚙️) 💪 `raise`.
    
    &amp; 👆 💚 🍵 👉 ⚠ 🌐 ⏮️ FastAPI.
    
    👆 💪 🚮 🛃 ⚠ 🐕‍🦺 ⏮️ `@app.exception_handler()`:
    
    ```Python hl_lines="5-7  13-18  24"
    {!../../../docs_src/handling_errors/tutorial003.py!}
    ```
    
    📥, 🚥 👆 📨 `/unicorns/yolo`, *➡ 🛠️* 🔜 `raise` `UnicornException`.
    
    ✋️ ⚫️ 🔜 🍵 `unicorn_exception_handler`.
    
    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)
  8. docs/ja/docs/tutorial/handling-errors.md

    あなた(または使用しているライブラリ)が`raise`するかもしれないカスタム例外`UnicornException`があるとしましょう。
    
    そして、この例外をFastAPIでグローバルに処理したいと思います。
    
    カスタム例外ハンドラを`@app.exception_handler()`で追加することができます:
    
    ```Python hl_lines="5 6 7  13 14 15 16 17 18  24"
    {!../../../docs_src/handling_errors/tutorial003.py!}
    ```
    
    ここで、`/unicorns/yolo`をリクエストすると、*path operation*は`UnicornException`を`raise`します。
    
    しかし、これは`unicorn_exception_handler`で処理されます。
    
    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)
  9. fastapi/applications.py

            from fastapi.responses import JSONResponse
    
    
            class UnicornException(Exception):
                def __init__(self, name: str):
                    self.name = name
    
    
            app = FastAPI()
    
    
            @app.exception_handler(UnicornException)
            async def unicorn_exception_handler(request: Request, exc: UnicornException):
                return JSONResponse(
                    status_code=418,
    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)
Back to top