Bird
0
0

What will be the HTTP status code and response body if the following FastAPI endpoint raises a ValueError without a custom exception handler?

medium📝 component behavior Q5 of 15
FastAPI - Error Handling
What will be the HTTP status code and response body if the following FastAPI endpoint raises a ValueError without a custom exception handler? ```python from fastapi import FastAPI app = FastAPI() @app.get("/test") async def test(): raise ValueError("Invalid value") ```
A500 Internal Server Error with default HTML error page
B400 Bad Request with JSON error message
C422 Unprocessable Entity with validation error details
D404 Not Found with empty body
Step-by-Step Solution
Solution:
  1. Step 1: Identify default FastAPI behavior for unhandled exceptions

    FastAPI returns a 500 Internal Server Error for unhandled exceptions like ValueError.
  2. Step 2: Understand default response format

    By default, the response is an HTML error page, not JSON, unless a custom handler is defined.
  3. Final Answer:

    500 Internal Server Error with default HTML error page -> Option A
  4. Quick Check:

    Unhandled exceptions = 500 error with HTML page [OK]
Quick Trick: Unhandled exceptions return 500 with HTML error by default [OK]
Common Mistakes:
MISTAKES
  • Expecting JSON error without custom handler
  • Confusing 422 validation errors with runtime exceptions
  • Assuming 400 or 404 status codes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes