08-异常处理

from fastapi import FastAPI, HTTPException

@app.get('/news/{id}')
async def get_news(id: int):
    id_list = [1, 2, 3, 4, 5, 6]
    if id not in id_list:
        raise HTTPException(status_code=404, detail="当前id不存在")
    return {"id": id}
posted @ 2026-03-14 22:18  Clefairy  阅读(1)  评论(0)    收藏  举报