potiuk commented on code in PR #39055:
URL: https://github.com/apache/airflow/pull/39055#discussion_r1567067801
##########
airflow/www/extensions/init_views.py:
##########
@@ -220,90 +203,100 @@ def resolve(self, operation):
return _LazyResolution(self.resolve_function_from_operation_id,
operation_id)
-class _CustomErrorRequestBodyValidator(RequestBodyValidator):
- """Custom request body validator that overrides error messages.
-
- By default, Connextion emits a very generic *None is not of type 'object'*
- error when receiving an empty request body (with the view specifying the
- body as non-nullable). We overrides it to provide a more useful message.
- """
-
- def validate_schema(self, data, url):
- if not self.is_null_value_valid and data is None:
- raise BadRequestProblem(detail="Request body must not be empty")
- return super().validate_schema(data, url)
+base_paths: list[str] = ["/auth/fab/v1"] # contains the list of base paths
that have api endpoints
-base_paths: list[str] = [] # contains the list of base paths that have api
endpoints
-
-
-def init_api_error_handlers(app: Flask) -> None:
+def init_api_error_handlers(connexion_app: connexion.FlaskApp) -> None:
"""Add error handlers for 404 and 405 errors for existing API paths."""
from airflow.www import views
- @app.errorhandler(404)
- def _handle_api_not_found(ex):
+ def _handle_api_not_found(error) -> ConnexionResponse | str:
+ from flask.globals import request
+
if any([request.path.startswith(p) for p in base_paths]):
# 404 errors are never handled on the blueprint level
# unless raised from a view func so actual 404 errors,
# i.e. "no route for it" defined, need to be handled
# here on the application level
- return common_error_handler(ex)
- else:
- return views.not_found(ex)
-
- @app.errorhandler(405)
- def _handle_method_not_allowed(ex):
- if any([request.path.startswith(p) for p in base_paths]):
- return common_error_handler(ex)
- else:
- return views.method_not_allowed(ex)
-
- app.register_error_handler(ProblemException, common_error_handler)
+ return connexion_app._http_exception(error)
+ return views.not_found(error)
+ def _handle_api_method_not_allowed(error) -> ConnexionResponse | str:
+ from flask.globals import request
-def init_api_connexion(app: Flask) -> None:
+ if any([request.path.startswith(p) for p in base_paths]):
+ return connexion_app._http_exception(error)
+ return views.method_not_allowed(error)
+
+ def _handle_redirect(
Review Comment:
@RobbeSneyders - here is a strange one that I need your comments on. When
we run our tests with TestClient from Strlette, we got redirect errors returned
by Connection - but they contained no `Location` header. Which mens that even
if we set `follow_redirect=True` in the client, the redirects have not been
followed, because redirects in httpx client only happen when "Location" header
is present. It could be an error somewhere in the stack - I am not sure. We
workarounded it with those custom redirect handlers - but I am not sure if this
is correct way of doing it (or maybe that is a bug that should be fixed
somewhere in connexion/starlette?)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]