SOARDO
Software Engineer (SDE)fastapiintermediate3 interactive MCQs in app

HTTPException & Custom Exception Handlers

HTTPException for semantic client status codescustom @app.exception_handler domain mappinghiding internal stack/SQL traces from HTTP JSON

Raise `HTTPException(status_code=404, detail="Mission not found")` for expected client/resource errors (`400/401/403/404/409`), and register domain `@app.exception_handler(AppError)` handlers translating domain exceptions cleanly into consistent JSON (`{error, code}`) while keeping internal SQL/provider stack traces strictly in server logs (never HTTP response bodies!).

`@app.exception_handler(UpstreamLLMError)` logs upstream HTTP details internally and returns HTTP `502` `{"error": "Grading service unavailable", "code": "LLM_UNAVAILABLE"}`!
returning raw `str(err)` in HTTP 500 payloads leaks database table names, file paths, or upstream API keys to attackers/students.
FastAPI — Handling Errors (Official)read ↗

Practice HTTPException & Custom Exception Handlers with 3 graded MCQs & written feedback.

Take SOARDO’s free 12-question diagnostic to see how strong you are across your target role and unlock adaptive daily missions.

Test yourself free on SOARDO →View full Software Engineer roadmap

More Software Engineer Study Guides