Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Adds fallback to res.text in billing error handler #21904

Merged
merged 3 commits into from
Apr 26, 2024
Merged
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
7 changes: 6 additions & 1 deletion ee/billing/billing_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import requests
import structlog
from django.utils import timezone
from requests.exceptions import JSONDecodeError

Check failure on line 8 in ee/billing/billing_manager.py

View workflow job for this annotation

GitHub Actions / Python code quality checks

Module "requests.exceptions" has no attribute "JSONDecodeError"
from rest_framework.exceptions import NotAuthenticated
from sentry_sdk import capture_exception

Expand Down Expand Up @@ -44,7 +45,11 @@
def handle_billing_service_error(res: requests.Response, valid_codes=(200, 404, 401)) -> None:
if res.status_code not in valid_codes:
logger.error(f"Billing service returned bad status code: {res.status_code}, body: {res.text}")
raise Exception(f"Billing service returned bad status code: {res.status_code}", f"body:", res.json())
try:
response = res.json()
raise Exception(f"Billing service returned bad status code: {res.status_code}", f"body:", response)
except JSONDecodeError:
raise Exception(f"Billing service returned bad status code: {res.status_code}", f"body:", res.text)


class BillingManager:
Expand Down
Loading