vincbeck commented on code in PR #45472:
URL: https://github.com/apache/airflow/pull/45472#discussion_r1907420844
##########
providers/src/airflow/providers/fab/www/extensions/init_views.py:
##########
@@ -78,6 +108,59 @@ def validate_schema(self, data, url):
return super().validate_schema(data, url)
+base_paths: list[str] = [] # contains the list of base paths that have api
endpoints
+
+
+def init_api_error_handlers(app: Flask) -> None:
+ """Add error handlers for 404 and 405 errors for existing API paths."""
+
+ @app.errorhandler(404)
+ def _handle_api_not_found(ex):
+ 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:
+ from airflow.providers.fab.www.views import not_found
+
+ return 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:
+ from airflow.providers.fab.www.views import method_not_allowed
+
+ return method_not_allowed(ex)
+
+ app.register_error_handler(ProblemException, common_error_handler)
+
+
+def init_api_connexion(app: Flask) -> None:
Review Comment:
I agree. Though, removing it make some tests fail. Some tests in FAB
provider are using Rest API endpoints (e.g. `/api/v1/pools` in
`providers/tests/fab/auth_manager/api_endpoints/test_auth.py`). So we need to
update these tests as well. I prefer doing it in a separate PR because I think
this one is big enough already.
--
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]