diff --git a/ee/billing/billing_manager.py b/ee/billing/billing_manager.py index 53b625dff4256..f564ffb160a03 100644 --- a/ee/billing/billing_manager.py +++ b/ee/billing/billing_manager.py @@ -5,6 +5,7 @@ import requests import structlog from django.utils import timezone +from requests.exceptions import JSONDecodeError from rest_framework.exceptions import NotAuthenticated from sentry_sdk import capture_exception @@ -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: