Skip to content

Commit

Permalink
add fallback to res.text
Browse files Browse the repository at this point in the history
  • Loading branch information
Bianca Yang committed Apr 26, 2024
1 parent f87b54c commit 3733e89
Showing 1 changed file with 6 additions and 1 deletion.
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 build_billing_token(license: License, organization: Organization):
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

0 comments on commit 3733e89

Please sign in to comment.