- Sort Score
- Result 10 results
- Languages All
Results 1 - 10 of 28 for exception_handler (0.31 sec)
-
docs_src/handling_errors/tutorial006.py
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)}")
Python - Registered: Sun Apr 21 07:19:11 GMT 2024 - Last Modified: Sun Aug 09 11:10:33 GMT 2020 - 928 bytes - Viewed (0) -
tests/test_exception_handlers.py
from fastapi.testclient import TestClient from starlette.responses import JSONResponse def http_exception_handler(request, exception): return JSONResponse({"exception": "http-exception"}) def request_validation_exception_handler(request, exception): return JSONResponse({"exception": "request-validation"}) def server_error_exception_handler(request, exception): return JSONResponse(status_code=500, content={"exception": "server-error"})
Python - Registered: Sun Apr 21 07:19:11 GMT 2024 - Last Modified: Thu Feb 17 12:40:12 GMT 2022 - 1.9K bytes - Viewed (0) -
docs_src/handling_errors/tutorial004.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): return PlainTextResponse(str(exc), status_code=400)
Python - Registered: Sun Apr 21 07:19:11 GMT 2024 - Last Modified: Thu Mar 26 19:09:53 GMT 2020 - 762 bytes - Viewed (0) -
fastapi/exception_handlers.py
) async def request_validation_exception_handler( request: Request, exc: RequestValidationError ) -> JSONResponse: return JSONResponse( status_code=HTTP_422_UNPROCESSABLE_ENTITY, content={"detail": jsonable_encoder(exc.errors())}, ) async def websocket_request_validation_exception_handler( websocket: WebSocket, exc: WebSocketRequestValidationError ) -> None:
Python - Registered: Sun Apr 21 07:19:11 GMT 2024 - Last Modified: Sun Jun 11 19:08:14 GMT 2023 - 1.3K bytes - Viewed (0) -
guava-tests/test/com/google/common/util/concurrent/ThreadFactoryBuilderTest.java
} public void testUncaughtExceptionHandler_custom() { assertEquals( UNCAUGHT_EXCEPTION_HANDLER, builder .setUncaughtExceptionHandler(UNCAUGHT_EXCEPTION_HANDLER) .build() .newThread(monitoredRunnable) .getUncaughtExceptionHandler()); } public void testBuildMutateBuild() {
Java - Registered: Fri Apr 12 12:43:09 GMT 2024 - Last Modified: Wed Sep 06 17:04:31 GMT 2023 - 7.5K bytes - Viewed (0) -
android/guava-tests/test/com/google/common/util/concurrent/ThreadFactoryBuilderTest.java
} public void testUncaughtExceptionHandler_custom() { assertEquals( UNCAUGHT_EXCEPTION_HANDLER, builder .setUncaughtExceptionHandler(UNCAUGHT_EXCEPTION_HANDLER) .build() .newThread(monitoredRunnable) .getUncaughtExceptionHandler()); } public void testBuildMutateBuild() {
Java - Registered: Fri Apr 26 12:43:10 GMT 2024 - Last Modified: Wed Sep 06 17:04:31 GMT 2023 - 7.5K bytes - Viewed (0) -
docs_src/handling_errors/tutorial005.py
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=status.HTTP_422_UNPROCESSABLE_ENTITY,
Python - Registered: Sun Apr 21 07:19:11 GMT 2024 - Last Modified: Thu Mar 26 19:09:53 GMT 2020 - 667 bytes - Viewed (0) -
docs_src/handling_errors/tutorial003.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, content={"message": f"Oops! {exc.name} did something. There goes a rainbow..."}, )
Python - Registered: Sun Apr 21 07:19:11 GMT 2024 - Last Modified: Thu Mar 26 19:09:53 GMT 2020 - 626 bytes - Viewed (0) -
docs/de/docs/tutorial/handling-errors.md
Sie könnten einen benutzerdefinierten Exceptionhandler mittels `@app.exception_handler()` hinzufügen: ```Python hl_lines="5-7 13-18 24" {!../../../docs_src/handling_errors/tutorial003.py!} ``` Wenn Sie nun `/unicorns/yolo` anfragen, `raise`d die *Pfadoperation* eine `UnicornException`. Aber diese wird von `unicorn_exception_handler` gehandhabt.
Plain Text - Registered: Sun Apr 21 07:19:11 GMT 2024 - Last Modified: Sat Mar 30 20:28:29 GMT 2024 - 10.6K bytes - Viewed (0) -
docs/ru/docs/tutorial/handling-errors.md
Можно добавить собственный обработчик исключений с помощью `@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 21 07:19:11 GMT 2024 - Last Modified: Fri Mar 22 01:42:11 GMT 2024 - 14.5K bytes - Viewed (0)