From 1c14d98a9f9c4472ce78cc55319257c8391e1d51 Mon Sep 17 00:00:00 2001 From: cb-alish Date: Wed, 10 Sep 2025 09:33:22 +0530 Subject: [PATCH 1/2] new exception type addition --- chargebee/__init__.py | 1 + chargebee/api_error.py | 8 ++++++++ chargebee/http_request.py | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/chargebee/__init__.py b/chargebee/__init__.py index ea285ad..a1ea3ec 100644 --- a/chargebee/__init__.py +++ b/chargebee/__init__.py @@ -3,6 +3,7 @@ PaymentError, InvalidRequestError, OperationFailedError, + UbbBatchIngestionInvalidRequestError, ) from chargebee.filters import Filters from chargebee.main import Chargebee diff --git a/chargebee/api_error.py b/chargebee/api_error.py index f47feed..053a324 100644 --- a/chargebee/api_error.py +++ b/chargebee/api_error.py @@ -1,4 +1,5 @@ class APIError(Exception): + def __init__(self, http_code, json_obj, headers=None): Exception.__init__(self, json_obj.get("message")) self.json_obj = json_obj @@ -27,3 +28,10 @@ def __init__(self, http_code, json_obj, headers=None): class OperationFailedError(APIError): def __init__(self, http_code, json_obj, headers=None): APIError.__init__(self, http_code, json_obj, headers) + + +class UbbBatchIngestionInvalidRequestError(APIError): + def __init__(self, http_code, json_obj, headers=None): + APIError.__init__(self, http_code, json_obj, headers) + self.batch_id = json_obj.get("batch_id") + self.failed_events = json_obj.get("failed_events") diff --git a/chargebee/http_request.py b/chargebee/http_request.py index 217beb5..3420155 100644 --- a/chargebee/http_request.py +++ b/chargebee/http_request.py @@ -14,6 +14,7 @@ PaymentError, InvalidRequestError, OperationFailedError, + UbbBatchIngestionInvalidRequestError, ) from chargebee import compat, util, environment from chargebee.main import Chargebee @@ -365,5 +366,9 @@ def handle_api_resp_error(url, http_code, resp_json, response_headers=None): raise OperationFailedError(http_code, resp_json, response_headers) elif "invalid_request" == resp_json.get("type"): raise InvalidRequestError(http_code, resp_json, response_headers) + elif "ubb_batch_ingestion_invalid_request" == resp_json.get("type"): + raise UbbBatchIngestionInvalidRequestError( + http_code, resp_json, response_headers + ) else: raise APIError(http_code, resp_json, response_headers) From 18a5d5aa36d2c364c170027ceb7177e0a90e5ea5 Mon Sep 17 00:00:00 2001 From: cb-alish Date: Wed, 10 Sep 2025 15:13:47 +0530 Subject: [PATCH 2/2] Bug Fix: double parsing of json request one by chargebee-python and other by httpx --- chargebee/request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chargebee/request.py b/chargebee/request.py index d81722f..7422b6a 100644 --- a/chargebee/request.py +++ b/chargebee/request.py @@ -70,7 +70,7 @@ def send( params = {} ser_params = ( - json.dumps(params) + params if isJsonRequest else util.serialize(params, None, None, jsonKeys) )