Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 15 additions & 10 deletions src/sentry/seer/assisted_query/issues_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def execute_issues_query(
stats_period: str = "7d",
sort: str | None = None,
limit: int = 25,
) -> list[dict[str, Any]] | None:
) -> list[dict[str, Any]] | dict[str, Any] | None:
"""
Execute an issues query by calling the issues endpoint.

Expand All @@ -492,7 +492,7 @@ def execute_issues_query(
limit: Number of results to return (default 25)

Returns:
List of issues, or None if organization doesn't exist
List of issues, dict with error key if 400 error occurred, or None if organization doesn't exist
"""
try:
organization = Organization.objects.get(id=org_id)
Expand All @@ -515,14 +515,19 @@ def execute_issues_query(
if sort:
params["sort"] = sort

resp = client.get(
auth=api_key,
user=None,
path=f"/organizations/{organization.slug}/issues/",
params=params,
)

return resp.data
try:
resp = client.get(
auth=api_key,
user=None,
path=f"/organizations/{organization.slug}/issues/",
params=params,
)
return resp.data
except client.ApiError as e:
if e.status_code == 400:
error_detail = e.body.get("detail") if isinstance(e.body, dict) else None
return {"error": str(error_detail) if error_detail else str(e.body)}
raise


def get_issues_stats(
Expand Down
21 changes: 13 additions & 8 deletions src/sentry/seer/explorer/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,19 @@ def execute_table_query(
# Remove None values
params = {k: v for k, v in params.items() if v is not None}

# Call sentry API client. This will raise API errors for non-2xx / 3xx status.
resp = client.get(
auth=ApiKey(organization_id=organization.id, scope_list=["org:read", "project:read"]),
user=None,
path=f"/organizations/{organization.slug}/events/",
params=params,
)
return {"data": resp.data["data"]}
try:
resp = client.get(
auth=ApiKey(organization_id=organization.id, scope_list=["org:read", "project:read"]),
user=None,
path=f"/organizations/{organization.slug}/events/",
params=params,
)
return {"data": resp.data["data"]}
except client.ApiError as e:
if e.status_code == 400:
error_detail = e.body.get("detail") if isinstance(e.body, dict) else None
return {"error": str(error_detail) if error_detail else str(e.body)}
raise


def execute_timeseries_query(
Expand Down
Loading