Skip to content

Commit 7a97d5c

Browse files
authored
fix(serve): return 404 status code when application or deployment not found (#51442) (#65584)
## Description Makes the Serve dashboard scale endpoint report client errors with 404 status code instead of 400 when an application or deployment is not found. #51417 added the `HTTPStatusCode` enum and the `rest_response(status_code=...)` plumbing, but adoption across dashboard modules is ongoing. **Backend (`python/ray/dashboard/modules/serve/serve_head.py`):** - In `scale_deployment`, when `ValueError` with `"not found"` occurred (looking up a nonexistent application or deployment), the endpoint returned HTTP 400 (Bad Request). Scaling a nonexistent resource is a client error representing a missing resource, so it now returns HTTP 404 (Not Found). ## Related issues Related to #51442 (umbrella: revisit Ray dashboard API status codes). Since #51442 is an umbrella issue, this PR covers the `serve_head.py` scope only, allowing each dashboard module to be reviewed independently. ## Tests Updated the existing unit test `test_error_case` in `python/ray/dashboard/modules/serve/tests/test_serve_dashboard.py`: - Verified that scaling a nonexistent application (`app_name="nonexistent"`) returns HTTP status code 404 instead of 400. ## Not a duplicate Checked existing open issues and PRs for #51442. No active PR currently addresses status code fixes for `serve_head.py`. Commented on #51442 prior to working on this scope. Signed-off-by: Vũ Hoàng Minh <vhminh23@clc.fitus.edu.vn>
1 parent 1c018ee commit 7a97d5c

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

python/ray/dashboard/modules/serve/serve_head.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ async def scale_deployment(self, req: Request) -> Response:
264264
return self._create_json_response({"error": str(e.cause)}, 412)
265265
if isinstance(e, ValueError) and "not found" in str(e):
266266
return self._create_json_response(
267-
{"error": "Application or Deployment not found"}, 400
267+
{"error": "Application or Deployment not found"}, 404
268268
)
269269
else:
270270
logger.error(

python/ray/dashboard/modules/serve/tests/test_serve_dashboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ def test_error_case(self, ray_start_stop):
969969
json={"target_num_replicas": 2},
970970
timeout=30,
971971
)
972-
assert error_response.status_code == 400
972+
assert error_response.status_code == 404
973973
assert "not found" in error_response.json()["error"].lower()
974974

975975
error_response = requests.post(

0 commit comments

Comments
 (0)