Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion python/ray/dashboard/state_api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ async def handle_list_api(
error_message="",
result=asdict(result),
)
except ValueError as e:
return do_reply(success=False, error_message=str(e), result=None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While catching ValueError is correct, this type of error indicates a client-side issue (invalid input), which should ideally return a 400 Bad Request status code rather than a 500 Internal Server Error. The do_reply function returns a 500 status for failures. To be more semantically correct with HTTP standards, it's better to use rest_response directly here to return a 400 status.

        return rest_response(
            status_code=HTTPStatusCode.BAD_REQUEST,
            message=str(e),
            result=None,
            convert_google_style=False,
        )

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same comment as the AI :)

500 should really never be exposed to the user unless there is some unexpected/unhandled exception. I know this is some tech debt/cruft though that you didn't add. If you don't mind, it would be great to improve it in a separate PR to return a 400 instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea i can take care of it, thanks for review!

except DataSourceUnavailable as e:
return do_reply(success=False, error_message=str(e), result=None)

Expand All @@ -70,7 +72,9 @@ def options_from_req(req: aiohttp.web.Request) -> ListApiOptions:
if limit > RAY_MAX_LIMIT_FROM_API_SERVER:
raise ValueError(
f"Given limit {limit} exceeds the supported "
f"limit {RAY_MAX_LIMIT_FROM_API_SERVER}. Use a lower limit."
f"Given limit {limit} exceeds the supported "
f"limit {RAY_MAX_LIMIT_FROM_API_SERVER}. Use a lower limit, or set the "
f"`RAY_MAX_LIMIT_FROM_API_SERVER` environment variable to a larger value."
)

timeout = int(req.query.get("timeout", 30))
Expand Down