A deliberate missing record
Take your time, follow the code and check your understanding.
The codeHTTP and validation
@app.get("/products/{product_id}")
def product(product_id: int):
if product_id not in products:
return {"error": "Missing"}Your answer4 min · no timer
Show solution and explanation
Returning an ordinary dictionary normally produces a 200 response. Raise HTTPException to set the intended error status.
Raise HTTPException(status_code=404, detail="Missing") to return a 404.