Skip to main content
BackAnt uses a custom 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

Import APIException in your service and raise it for expected error conditions:

How it reaches the client

app.py registers APIException with Flask’s error handler:
Any APIException raised anywhere in the request lifecycle (route, service, repository) is automatically caught and returned as:

Passing extra data

Use payload to include additional fields in the error response:
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 an APIException will propagate as a 500 Internal Server Error. Use myLogger.exception(e) to log the full traceback before re-raising or wrapping: