APIException class for all expected errors. Raise it from any layer — the error handler registered in app.py catches it and returns a formatted JSON response.
APIException
Raising errors
ImportAPIException in your service and raise it for expected error conditions:
How it reaches the client
app.py registers APIException with Flask’s error handler:
APIException raised anywhere in the request lifecycle (route, service, repository) is automatically caught and returned as:
Passing extra data
Usepayload to include additional fields in the error response:
Common status codes
Handling database errors
Wrap repository calls in the service when you need to translate database exceptions:Unhandled exceptions
Any exception that is not anAPIException will propagate as a 500 Internal Server Error. Use myLogger.exception(e) to log the full traceback before re-raising or wrapping: