Skip to content

Commit 0fe69b9

Browse files
jscheffliharsh02
authored andcommitted
Improve error handling in edge worker on 405 (apache#60425)
* Improve Edge Worker error handling on HTTP 405 * Add pytest
1 parent 2de0c35 commit 0fe69b9

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

providers/edge3/src/airflow/providers/edge3/cli/worker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ async def start(self):
269269
logger.error(str(e))
270270
raise SystemExit(str(e))
271271
except ClientResponseError as e:
272-
if e.status == HTTPStatus.NOT_FOUND:
272+
# Note: Method not allowed is raised by FastAPI if the API is not enabled (not 404)
273+
if e.status in {HTTPStatus.NOT_FOUND, HTTPStatus.METHOD_NOT_ALLOWED}:
273274
raise SystemExit(
274275
"Error: API endpoint is not ready, please set [edge] api_enabled=True. Or check if the URL is correct to your deployment."
275276
)

providers/edge3/tests/unit/edge3/cli/test_worker.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,21 @@ async def test_version_mismatch(self, mock_set_state, worker_with_job):
396396
await worker_with_job.heartbeat()
397397
assert worker_with_job.drain
398398

399+
@pytest.mark.parametrize(
400+
"http_error",
401+
[
402+
pytest.param(404, id="HTTP 404 Not Found"),
403+
pytest.param(405, id="HTTP 405 Method Not Allowed"),
404+
],
405+
)
399406
@patch("airflow.providers.edge3.cli.worker.worker_register")
400-
async def test_start_missing_apiserver(self, mock_register_worker, worker_with_job: EdgeWorker):
407+
async def test_start_missing_apiserver(
408+
self, mock_register_worker, http_error, worker_with_job: EdgeWorker
409+
):
401410
mock_register_worker.side_effect = ClientResponseError(
402411
request_info=RequestInfo(url=URL("mock.com"), method="GET", headers=None), # type:ignore[arg-type]
403-
message="Something with 404:NOT FOUND means API is not active",
404-
status=404,
412+
message=f"Something with {http_error}: Means API is not active",
413+
status=http_error,
405414
history=(),
406415
)
407416
with pytest.raises(SystemExit, match=r"API endpoint is not ready"):

0 commit comments

Comments
 (0)