Skip to content

Commit

Permalink
fix: Handle connection errors (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgrayston-paddle authored Oct 8, 2024
1 parent 40a5008 commit 55a9f85
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Check our main [developer changelog](https://developer.paddle.com/?utm_source=dx
- `CustomersClient.credit_balances` can now be filtered by `currency_code`
- Transaction payments `payment_method_id` can be `string` or `None`
- `paddle_billing.Notifications.Verifier` `verify()` now expects `request` to be `paddle_billing.Notifications.Requests.Request` protocol
- Client connection errors will be raised as `requests.exceptions.ConnectionError` instead of an `AttributeError`

### Removed

Expand Down
3 changes: 1 addition & 2 deletions paddle_billing/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,9 @@ def _make_request(

return response
except RequestException as e:
self.status_code = e.response.status_code

api_error = None
if e.response is not None:
self.status_code = e.response.status_code
response_parser = ResponseParser(e.response)
api_error = response_parser.get_error()

Expand Down
14 changes: 14 additions & 0 deletions tests/Functional/Client/test_Client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from json import loads, dumps
from pytest import mark, raises
from urllib.parse import unquote
import requests

from paddle_billing.Exceptions.ApiError import ApiError
from paddle_billing.Exceptions.ApiErrors.AddressApiError import AddressApiError
Expand Down Expand Up @@ -155,3 +156,16 @@ def test_client_default_timeout(self, test_client, mock_requests):
test_client.client.post_raw(expected_request_url)

assert mock_requests.last_request.timeout == 60.0

def test_client_throws_connection_error(self, test_client, mock_requests):
expected_request_url = f"{test_client.base_url}/some/url"

mock_requests.post(expected_request_url, exc=requests.exceptions.ConnectionError("Some Connection Error"))

with raises(requests.exceptions.ConnectionError) as exception_info:
test_client.client.post_raw(expected_request_url)

exception = exception_info.value

assert isinstance(exception, RequestException)
assert str(exception) == "Some Connection Error"

0 comments on commit 55a9f85

Please sign in to comment.