Raise Custom Exception Classes
Define domain errors that map to JSON.
Errors That Speak Your Domain
Numbers like 400 are generic. A custom exception names the real problem, such as a payment that failed or a quota hit.
Subclass an Exception
You start by defining a class that inherits from Exception. This gives you a clear, raisable error of your own.
class PaymentError(Exception):
passAll lessons in this course
- abort and HTTP Error Codes
- Register errorhandler Functions
- Raise Custom Exception Classes
- Uniform JSON Error Envelopes