はじめての FastAPI(前編) https://qiita.com/uturned0/items/9c3d19c1f846a07ec779 の続き Handling Errors¶ HTTPException http://0.0.0.0:8000/err/1 にいくと 404 が返る。raise するだけで json がレスポンスになるの最高。 from fastapi import FastAPI, Body, Query, HTTPException items = {"foo": "The Foo Wrestlers"} @app.get("/err/{item_id}") async def read_item(item_id: str): if item_id not in items: raise HTTPException(status_code=404, detail