From afc6ec6b9c915201c816c741e85426883499929a Mon Sep 17 00:00:00 2001 From: Josh Willox Date: Wed, 20 Apr 2022 18:21:00 +1000 Subject: [PATCH] Fix `JSONDecodeError` with 204 responses --- upbankapi/client/_async.py | 2 ++ upbankapi/client/_sync.py | 2 ++ upbankapi/client/base.py | 1 + 3 files changed, 5 insertions(+) diff --git a/upbankapi/client/_async.py b/upbankapi/client/_async.py index 0368dec..f868f44 100644 --- a/upbankapi/client/_async.py +++ b/upbankapi/client/_async.py @@ -61,6 +61,8 @@ async def api( headers=self._headers, url=f"{BASE_URL}{endpoint}", ) as response: + if response.status == 204: + return True return self._handle_response(await response.json(), response.status) async def ping(self) -> str: diff --git a/upbankapi/client/_sync.py b/upbankapi/client/_sync.py index 7e6e7bd..0c70b34 100644 --- a/upbankapi/client/_sync.py +++ b/upbankapi/client/_sync.py @@ -50,6 +50,8 @@ def api( headers=self._headers, url=f"{BASE_URL}{endpoint}", ) + if response.status_code == 204: + return True return self._handle_response(response.json(), response.status_code) def ping(self) -> str: diff --git a/upbankapi/client/base.py b/upbankapi/client/base.py index e968fc0..2437d64 100644 --- a/upbankapi/client/base.py +++ b/upbankapi/client/base.py @@ -45,6 +45,7 @@ def api( @staticmethod def _handle_response(data: Dict, status: int) -> Union[bool, Dict]: + # this should have been checked by any calling methods already if status == 204: return True