Flask, by default contains an exception handler, which FireTail’s app can proxy to with the add_error_handler method. You can hook either on status codes or on a specific exception type.
FireTail is moving from returning flask responses on errors to throwing exceptions that are a subclass of firetail.problem. So far exceptions thrown in the OAuth decorator have been converted.
The goal here is to make the API returning the 404 status code when there is a NotFoundException (instead of 500).
Firstly, it’s possible to declare what Exception must be handled:
In this way, it’s possible to raise anywhere the NotFoundException or its subclasses and we know the API will return 404 status code.
By default, FireTail exceptions are JSON serialized according to Problem Details for HTTP APIs
The application can return errors using firetail.problem or exceptions that inherit from both firetail.ProblemException and a werkzeug.exceptions.HttpException subclass (for example werkzeug.exceptions.Forbidden). An example of this is the firetail.exceptions.OAuthProblem exception:
To custom render an exception when you boot your FireTail application you can hook into a custom exception and render it in some sort of custom format. For example:
There are several exception types in FireTail that contain extra information to help you render appropriate messages to your user beyond the default description and status code: