Skip to content

Commit

Permalink
Fix JSONDecodeError with 204 responses
Browse files Browse the repository at this point in the history
  • Loading branch information
jcwillox committed Apr 20, 2022
1 parent 1022850 commit afc6ec6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions upbankapi/client/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions upbankapi/client/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions upbankapi/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit afc6ec6

Please sign in to comment.