- Sort Score
- Result 10 results
- Languages All
Results 1 - 4 of 4 for UnicornException (0.06 sec)
-
docs_src/handling_errors/tutorial003_py39.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,Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Wed Dec 17 20:41:43 UTC 2025 - 626 bytes - Viewed (0) -
docs/en/docs/tutorial/handling-errors.md
You can add custom exception handlers with <a href="https://www.starlette.dev/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()`:
Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Wed Dec 17 20:41:43 UTC 2025 - 9K bytes - Viewed (0) -
docs/zh/docs/tutorial/handling-errors.md
## 安装自定义异常处理器 添加自定义处理器,要使用 [Starlette 的异常工具](https://www.starlette.dev/exceptions/)。 假设要触发的自定义异常叫作 `UnicornException`。 且需要 FastAPI 实现全局处理该异常。 此时,可以用 `@app.exception_handler()` 添加自定义异常控制器: {* ../../docs_src/handling_errors/tutorial003.py hl[5:7,13:18,24] *} 请求 `/unicorns/yolo` 时,路径操作会触发 `UnicornException`。 但该异常将会被 `unicorn_exception_handler` 处理。 接收到的错误信息清晰明了,HTTP 状态码为 `418`,JSON 内容如下: ```JSON
Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Sat Oct 11 17:48:49 UTC 2025 - 8.2K bytes - Viewed (0) -
docs/es/docs/tutorial/handling-errors.md
Supongamos que tienes una excepción personalizada `UnicornException` que tú (o un paquete que usas) podrías lanzar. Y quieres manejar esta excepción globalmente con FastAPI. Podrías agregar un manejador de excepciones personalizado con `@app.exception_handler()`:
Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Wed Dec 17 20:41:43 UTC 2025 - 9.7K bytes - Viewed (0)