I have error handlers in my app. I add these using connexion's add_error_handler which is calling flask's register_error_handler. I wish to restructure the error data that is returned by my endpoints in this handler. However, since I have so many unit tests reliant on the old structure, I wish to implement the new error structure for a subset of endpoints first. I believe I can do this as follows:
from flask import request
new_endpoints = ("/new_endpoint",)
def is_new_endpoint():
return request.path in new_endpoints
def my_error_handler(e):
if is_new_endpoint():
return FlaskApi.response(new_error_response(e))
else:
return FlaskApi.response(old_error_response(e))
Is there another approach to doing this? The problem I have is that I believe that the is_new_endpoint function might get messy.
I define my endpoints in a yaml file, and for each endpoint, I have an operationId which specifies the python function associated with the endpoint. Maybe I could decorate these functions to define them as new and have this information available in the error handler. Could this be a possible alternative approach? Could I use flask.g for this?