Skip to content

Commit 1970c4a

Browse files
authored
Fixed issue when raw_response is empty. (#39)
Fixes #35
1 parent 03af966 commit 1970c4a

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

Adyen/client.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,8 @@ def _handle_response(self, url, raw_response, raw_request, status_code, headers,
414414
response = {}
415415
# If the result can't be parsed into json, most likely is raw html.
416416
# Some response are neither json or raw html, handle them here:
417-
418-
response = json_lib.loads(raw_response)
419-
417+
if raw_response:
418+
response = json_lib.loads(raw_response)
420419
# Pass raised error to error handler.
421420
self._handle_http_error(url,response,status_code,headers.get('pspReference'),raw_request,raw_response,headers,request_dict)
422421

@@ -488,10 +487,10 @@ def _handle_http_error(self, url, response_obj, status_code, psp_ref,
488487
elif status_code in [400, 422]:
489488
erstr = "Received validation error with errorCode: %s, message: %s, HTTP Code: %s. Please verify the values provided. Please reach out to support@adyen.com if the problem persists, providing the PSP reference: %s" % (response_obj["errorCode"],response_obj["message"], status_code, psp_ref)
490489

491-
raise ValueError(erstr)
490+
raise AdyenAPIValidationError(erstr)
492491
elif status_code == 401:
493492
erstr = "Unable to authenticate with Adyen's Servers. Please verify the credentials set with the Adyen base class. Please reach out to your Adyen Admin if the problem persists"
494-
raise ValueError(erstr)
493+
raise AdyenAPIAuthenticationError(erstr)
495494
elif status_code == 403:
496495
from . import username
497496

test/ModificationTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_capture_error_167(self):
3030
request['modificationAmount'] = {"value": "1234", "currency": "EUR"}
3131
request['originalReference'] = "YourOriginalReference"
3232
self.ady.client = self.test.create_client_from_file(422, request, 'test/mocks/capture-error-167.json')
33-
self.assertRaisesRegexp(ValueError,"Received validation error with errorCode: 167, message: Original pspReference required for this operation, HTTP Code: 422." +
33+
self.assertRaisesRegexp(Adyen.AdyenAPIValidationError,"Received validation error with errorCode: 167, message: Original pspReference required for this operation, HTTP Code: 422." +
3434
" Please verify the values provided. Please reach out to support@adyen.com if the problem persists, providing the PSP reference.*",
3535
self.ady.payment.capture, request)
3636

test/PaymentTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def test_error_401_mocked(self):
147147
"holderName": "John Doe"
148148
}
149149
self.ady.client = self.test.create_client_from_file(401, request, 'test/mocks/authorise-error-010.json')
150-
self.assertRaisesRegexp(ValueError, "Unable to authenticate with Adyen's Servers. Please verify the credentials set with the Adyen base class. Please reach out to your Adyen Admin if the problem persists" , self.ady.payment.authorise, request)
150+
self.assertRaisesRegexp(Adyen.AdyenAPIAuthenticationError, "Unable to authenticate with Adyen's Servers. Please verify the credentials set with the Adyen base class. Please reach out to your Adyen Admin if the problem persists" , self.ady.payment.authorise, request)
151151

152152

153153
TestPayments.client.http_force = "requests"

test/RecurringTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_disable_803(self):
4545
request["shopperReference"] = "ref"
4646
request["recurringDetailReference"] = "12345678889"
4747
self.ady.client = self.test.create_client_from_file(422, request, 'test/mocks/recurring/disable-error-803.json')
48-
self.assertRaisesRegexp(ValueError,
48+
self.assertRaisesRegexp(Adyen.AdyenAPIValidationError,
4949
"Received validation error with errorCode: 803, message: PaymentDetail not found, HTTP Code: 422.*",
5050
self.ady.recurring.disable, request)
5151

0 commit comments

Comments
 (0)