1. Learn
  2. /
  3. Courses
  4. /
  5. Deploying AI into Production with FastAPI

Connected

Exercise

Global exception handler

Your API to update inventory has been getting more use, and some users have started to complain that validation errors encoded in JSON are hard to read. Let's create a global error handler to return request validation errors as plain text.

The RequestValidationError exception has been pre-loaded for you.

Instructions

100 XP
  • Import the class for plain text responses.
  • Annotate validation_exception_handler as a global exception handler.
  • Return a plain text response for any validation exception.