- Sort Score
- Num 10 results
- Language All
Results 1 - 10 of 16 for exception_handler (0.12 seconds)
-
docs/en/docs/reference/fastapi.md
- put - post - delete - options - head - patch - trace - on_event - middlewareCreated: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Apr 18 19:53:19 GMT 2024 - 701 bytes - Click Count (0) -
docs_src/handling_errors/tutorial006_py310.py
from fastapi import FastAPI, HTTPException from fastapi.exception_handlers import ( 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)}")
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Feb 12 13:19:43 GMT 2026 - 928 bytes - Click Count (0) -
docs_src/handling_errors/tutorial004_py310.py
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) async def validation_exception_handler(request, exc: RequestValidationError): message = "Validation errors:"
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Feb 12 13:19:43 GMT 2026 - 920 bytes - Click Count (0) -
docs_src/handling_errors/tutorial005_py310.py
from fastapi.encoders import jsonable_encoder from fastapi.exceptions import RequestValidationError from fastapi.responses import JSONResponse from pydantic import BaseModel app = FastAPI() @app.exception_handler(RequestValidationError) async def validation_exception_handler(request: Request, exc: RequestValidationError): return JSONResponse( status_code=422,
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Feb 12 13:19:43 GMT 2026 - 626 bytes - Click Count (0) -
docs_src/handling_errors/tutorial003_py310.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,
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Feb 12 13:19:43 GMT 2026 - 626 bytes - Click Count (0) -
docs/es/docs/tutorial/handling-errors.md
Y quieres manejar esta excepción globalmente con FastAPI. Podrías agregar un manejador de excepciones personalizado con `@app.exception_handler()`: {* ../../docs_src/handling_errors/tutorial003_py310.py hl[5:7,13:18,24] *} Aquí, si solicitas `/unicorns/yolo`, la *path operation* lanzará un `UnicornException`.Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Mar 19 18:15:55 GMT 2026 - 9.6K bytes - Click Count (0) -
docs/tr/docs/tutorial/handling-errors.md
Diyelim ki sizin (ya da kullandığınız bir kütüphanenin) `raise` edebileceği `UnicornException` adında özel bir exception’ınız var. Ve bu exception’ı FastAPI ile global olarak handle etmek istiyorsunuz. `@app.exception_handler()` ile özel bir exception handler ekleyebilirsiniz: {* ../../docs_src/handling_errors/tutorial003_py310.py hl[5:7,13:18,24] *}
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Fri Mar 20 07:53:17 GMT 2026 - 9.7K bytes - Click Count (0) -
docs/zh/docs/tutorial/handling-errors.md
可以使用[与 Starlette 相同的异常处理工具](https://www.starlette.dev/exceptions/)添加自定义异常处理器。 假设有一个自定义异常 `UnicornException`(你自己或你使用的库可能会 `raise` 它)。 并且你希望用 FastAPI 在全局处理该异常。 此时,可以用 `@app.exception_handler()` 添加自定义异常处理器: {* ../../docs_src/handling_errors/tutorial003_py310.py hl[5:7,13:18,24] *} 这里,请求 `/unicorns/yolo` 时,路径操作会触发 `UnicornException`。 但该异常将会被 `unicorn_exception_handler` 处理。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) -
docs/en/docs/tutorial/handling-errors.md
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()`: {* ../../docs_src/handling_errors/tutorial003_py310.py hl[5:7,13:18,24] *} Here, if you request `/unicorns/yolo`, the *path operation* will `raise` a `UnicornException`.
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Mar 05 18:13:19 GMT 2026 - 8.9K bytes - Click Count (0) -
docs/zh-hant/docs/tutorial/handling-errors.md
你可以使用 [Starlette 的相同例外工具](https://www.starlette.dev/exceptions/) 來加入自訂例外處理器。 假設你有一個自訂例外 `UnicornException`,你(或你使用的函式庫)可能會 `raise` 它。 而你想用 FastAPI 全域處理這個例外。 你可以使用 `@app.exception_handler()` 加入自訂例外處理器: {* ../../docs_src/handling_errors/tutorial003_py310.py hl[5:7,13:18,24] *} 在這裡,如果你請求 `/unicorns/yolo`,該「路徑操作」會 `raise` 一個 `UnicornException`。 但它會被 `unicorn_exception_handler` 所處理。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)