-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: コアが見つからない例外を追加 * fix: 依存関係を明確化 * fix: `CoreNotFound` ハンドラの立ち位置を変更 * fix: エラーメッセージのテストを削除 * fix: `register_` → `configure_` へリネーム
- Loading branch information
Showing
6 changed files
with
46 additions
and
8 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
test/e2e/__snapshots__/test_missing_core/test_missing_core_422.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"""コア取得失敗のテスト""" | ||
|
||
from fastapi.testclient import TestClient | ||
from syrupy.assertion import SnapshotAssertion | ||
|
||
|
||
def test_missing_core_422(client: TestClient, snapshot_json: SnapshotAssertion) -> None: | ||
"""存在しないコアを指定するとエラーを返す。""" | ||
response = client.get("/supported_devices", params={"core_version": "4.0.4"}) | ||
assert response.status_code == 422 | ||
assert snapshot_json == response.json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""グローバルな例外ハンドラの定義と登録""" | ||
|
||
from fastapi import FastAPI, Request | ||
from fastapi.responses import JSONResponse | ||
|
||
from voicevox_engine.core.core_initializer import CoreNotFound | ||
|
||
|
||
def configure_global_exception_handlers(app: FastAPI) -> FastAPI: | ||
"""グローバルな例外ハンドラを app へ設定する。""" | ||
|
||
# 指定されたコアが見つからないエラー | ||
@app.exception_handler(CoreNotFound) | ||
async def cnf_exception_handler(request: Request, e: CoreNotFound) -> JSONResponse: | ||
return JSONResponse(status_code=422, content={"message": f"{str(e)}"}) | ||
|
||
return app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters