コンテンツにスキップ
per page, with , order by , clip by
Results of 1 - 1 of about 1 for UnicornException (0.001 sec.)
エラーハンドリング 9414
エラーハンドリング APIを使用しているクライアントにエラーを通知する必要がある状況はたくさんあります。 このクライアントは、フロントエンドを持つブラウザ、誰かのコード、IoTデバイスなどが考えられます。 クライアントに以下のようなことを伝える必要が ... ーティリティ を使用して追加することができます。 あなた(または使用しているライブラリ)が raise するかもしれないカスタム例外 UnicornException があるとしましょう。 そして、この例外をFastAPIでグローバルに処理したいと思います。 カスタム例外ハンドラを @app.exception_h ... で追加することができます: Python 3.8+ 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 ( UnicornE ... xception ) 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 r ...
https://man.mtool.work/fastapi/0.115/tutorial/handling-errors/
PREV 1 NEXT