Raising Your Own Exceptions in an API

An API's own rules raise exception classes named for each problem, such as TicketNotFound and StatusChangeNotAllowed, from plain functions that know nothing about HTTP, and @app.exception_handler turns each one into a status code and a JSON body, such as 404 or 409.

By

Updated

Cheat sheet: Raising Your Own Exceptions in an API
Category
FastAPI
Level
Journeyman
Tags
409 Conflict, Custom Exception (python), Exception Handler (fastapi), fastapi, rest-api