반응형 Handling Error1 Fast API 배우기 16부 - Handling Errors HTTP Exception HTTPException 클래스를 이용하면 에러를 일으킬 수 있다. from fastapi import FastAPI, HTTPException app = FastAPI() items = {"foo": "The Foo Wrestlers"} @app.get("/items/{item_id}") async def read_item(item_id: str): if item_id not in items: raise HTTPException(status_code=404, detail="Item not found") return {"item": items[item_id]} 상기의 코드는 클라이언트가 접근하려는 아이템이 없을경우 404 에러를 일이키는 코드이다. HTTPException은 파.. 2021. 11. 2. 이전 1 다음 반응형