Performance: Status code control
MEDIUM IMPACT
This affects how quickly the server responds and how efficiently the client handles the response, impacting perceived speed and interaction responsiveness.
from fastapi import FastAPI, HTTPException app = FastAPI() @app.get("/items/{item_id}") async def read_item(item_id: int): if item_id == 0: raise HTTPException(status_code=404, detail="Item not found") # Proper status code return {"item_id": item_id}
from fastapi import FastAPI app = FastAPI() @app.get("/items/{item_id}") async def read_item(item_id: int): if item_id == 0: return {"error": "Item not found"} # No status code set, defaults to 200 return {"item_id": item_id}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No explicit status code (default 200) | No direct DOM ops | No reflows triggered by status | Potential extra paint due to error UI updates | [X] Bad |
| Explicit status code with HTTPException | No direct DOM ops | No reflows triggered by status | Minimal paint cost due to clear error handling | [OK] Good |