Search Options

Display Count
Sort
Preferred Language
Advanced Search

Results 11 - 14 of 14 for unicorn_exception_handler (0.28 seconds)

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

    此时,可以用 `@app.exception_handler()` 添加自定义异常处理器:
    
    {* ../../docs_src/handling_errors/tutorial003_py310.py hl[5:7,13:18,24] *}
    
    这里,请求 `/unicorns/yolo` 时,路径操作会触发 `UnicornException`。
    
    但该异常将会被 `unicorn_exception_handler` 处理。
    
    你会收到清晰的错误信息,HTTP 状态码为 `418`,JSON 内容如下:
    
    ```JSON
    {"message": "Oops! yolo did something. There goes a rainbow..."}
    ```
    
    /// note | 技术细节
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 17:06:37 GMT 2026
    - 8.2K bytes
    - Click Count (0)
  2. docs/ko/docs/tutorial/handling-errors.md

    `@app.exception_handler()`로 커스텀 예외 핸들러를 추가할 수 있습니다:
    
    {* ../../docs_src/handling_errors/tutorial003_py310.py hl[5:7,13:18,24] *}
    
    여기서 `/unicorns/yolo`를 요청하면, *경로 처리*가 `UnicornException`을 `raise`합니다.
    
    하지만 `unicorn_exception_handler`가 이를 처리합니다.
    
    따라서 HTTP 상태 코드 `418`과 다음 JSON 내용을 가진 깔끔한 오류를 받게 됩니다:
    
    ```JSON
    {"message": "Oops! yolo did something. There goes a rainbow..."}
    ```
    
    /// note | 기술 세부사항
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 14:06:26 GMT 2026
    - 10.2K bytes
    - Click Count (0)
  3. docs/zh-hant/docs/tutorial/handling-errors.md

    你可以使用 `@app.exception_handler()` 加入自訂例外處理器:
    
    {* ../../docs_src/handling_errors/tutorial003_py310.py hl[5:7,13:18,24] *}
    
    在這裡,如果你請求 `/unicorns/yolo`,該「路徑操作」會 `raise` 一個 `UnicornException`。
    
    但它會被 `unicorn_exception_handler` 所處理。
    
    因此你會得到一個乾淨的錯誤回應,HTTP 狀態碼為 `418`,JSON 內容如下:
    
    ```JSON
    {"message": "Oops! yolo did something. There goes a rainbow..."}
    ```
    
    /// note | 技術細節
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 17:05:38 GMT 2026
    - 8.3K bytes
    - Click Count (0)
  4. fastapi/applications.py

                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,
                    content={"message": f"Oops! {exc.name} did something. There goes a rainbow..."},
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Wed Apr 01 16:16:24 GMT 2026
    - 178.6K bytes
    - Click Count (0)
Back to Top