Bird
0
0

When raising an HTTPException in FastAPI, which argument must you provide to specify the HTTP status code?

easy🧠 Conceptual Q2 of 15
FastAPI - Error Handling
When raising an HTTPException in FastAPI, which argument must you provide to specify the HTTP status code?
Ahttp_status
Bcode
Cstatus_code
Dstatus
Step-by-Step Solution
Solution:
  1. Step 1: Check HTTPException signature

    The HTTPException constructor requires a status_code parameter to define the HTTP status.
  2. Step 2: Verify other parameters

    Other parameters like detail are optional; status_code is mandatory.
  3. Final Answer:

    status_code is the correct parameter name -> Option C
  4. Quick Check:

    Use status_code to set HTTP status in HTTPException [OK]
Quick Trick: Use 'status_code' to set HTTP status in HTTPException [OK]
Common Mistakes:
MISTAKES
  • Using 'code' instead of 'status_code'
  • Using 'http_status' or 'status' which are invalid
  • Omitting the status code parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes