Skip to content

fix(sentry): handle empty/non-JSON error responses in validate_scopes - #6813

Merged
shahargl merged 1 commit into
keephq:mainfrom
apercivall:fix/sentry-validate-scopes-json-decode
Sep 13, 2026
Merged

shahargl merged 1 commit into
keephq:mainfrom
apercivall:fix/sentry-validate-scopes-json-decode

Conversation

@apercivall

Copy link
Copy Markdown
Contributor

Summary

Safely extracts error details during Sentry validate_scopes to prevent unhandled JSONDecodeError from crashing the entire validation check when Sentry returns an error response with an empty or non-JSON body.

Fixes #6812

Problem

In sentry_provider.py, validate_scopes checks scopes (event:read, project:read, project:write).
For project:write, it sends a POST request to {sentry_api}/projects/{org}/{project}/plugins/webhooks/.

When Sentry returns an error with an empty HTML body (e.g. HTTP 404 with 0 bytes, as the legacy /plugins/webhooks/ API has been deprecated by Sentry), calling response.json() raises requests.exceptions.JSONDecodeError.

Because this exception was unhandled:

  1. It crashed the entire validate_provider_scopes endpoint with an internal server error.
  2. The UI showed "Failed to revalidate scopes" and reported all scopes as "Not checked", even though event:read and project:read were fully valid and alerts were being ingested fine.

Fix

Added a helper method _extract_error_detail(response) that attempts to parse response.json().get("detail") or string representation, and cleanly falls back to f"HTTP {response.status_code}" if parsing fails. Applied across all error handling branches in validate_scopes.

When Sentry returns an error with an empty or non-JSON body (e.g. HTTP 404 from
deprecated /plugins/webhooks/ on project:write), calling response.json()
raises requests.exceptions.JSONDecodeError. This unhandled exception bubbles up
and crashes the entire validate_scopes call, causing all scopes to report 'Not checked'.

Wrap error detail extraction in a helper that falls back to f'HTTP {response.status_code}'
if JSON decoding fails or detail is missing.

Fixes #6812

@shahargl shahargl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@shahargl
shahargl merged commit 99e3ffd into keephq:main Sep 13, 2026
5 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Well done @apercivall! Two PRs merged already! 🎉🥳

With your second PR, you're on a roll, and your contributions are already making a difference. 🌟
Looking forward to seeing even more contributions from you. See you in Slack https://slack.keephq.dev 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Sentry provider validate_scopes crashes on empty response body from /plugins/webhooks/

2 participants