Skip to content

Commit ae927f9

Browse files
Fix error that occurs if payload is omitted (#12)
* Fix error that occurs if payload is omitted * Handle errors using response.raise_for_status() * Bump version to 1.0.2
1 parent 34731b3 commit ae927f9

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

authsignal/client.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ def track(self, user_id, action, payload=None, path=None):
7373
try:
7474
response = self.session.post(
7575
path,
76-
data=json.dumps(payload, cls=DecimalEncoder),
76+
data=json.dumps(payload if payload is not None else {}, cls=DecimalEncoder),
7777
auth=requests.auth.HTTPBasicAuth(self.api_key, ''),
7878
headers=headers,
7979
timeout=timeout,
8080
params=params)
81-
if response.status_code > 299:
82-
raise ApiException("Track Action Failed", path, http_status_code=response.status_code, api_error_message=response.json()["message"])
81+
response.raise_for_status()
82+
8383
return humps.decamelize(response.json())
8484
except requests.exceptions.RequestException as e:
8585
raise ApiException(str(e), path) from e
@@ -108,8 +108,8 @@ def get_action(self, user_id, action, idempotency_key, path=None):
108108
headers=headers,
109109
timeout=timeout,
110110
params=params)
111-
if response.status_code > 299:
112-
raise ApiException("Get Action Failed", path, http_status_code=response.status_code, api_error_message=response.json()["message"])
111+
response.raise_for_status()
112+
113113
return humps.decamelize(response.json())
114114
except requests.exceptions.RequestException as e:
115115
raise ApiException(str(e), path) from e
@@ -140,8 +140,8 @@ def get_user(self, user_id, redirect_url=None, path=None):
140140
headers=headers,
141141
timeout=timeout,
142142
params=params)
143-
if response.status_code > 299:
144-
raise ApiException("Get User Failed", path, http_status_code=response.status_code, api_error_message=response.json()["message"])
143+
response.raise_for_status()
144+
145145
return humps.decamelize(response.json())
146146
except requests.exceptions.RequestException as e:
147147
raise ApiException(str(e), path) from e
@@ -170,8 +170,7 @@ def enroll_verified_authenticator(self, user_id, authenticator_payload, path=No
170170
headers=headers,
171171
timeout=timeout,
172172
params=params)
173-
if response.status_code > 299:
174-
raise ApiException("Enroll Verified Authenticator Failed", path, http_status_code=response.status_code, api_error_message=response.json()["message"])
173+
response.raise_for_status()
175174
return humps.decamelize(response.json())
176175
except requests.exceptions.RequestException as e:
177176
raise ApiException(str(e), path) from e

authsignal/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '1.0.1'
1+
VERSION = '1.0.2'

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "authsignal"
3-
version = "1.0.1"
3+
version = "1.0.2"
44
description = "Authsignal Python SDK for Passwordless Step Up Authentication"
55
authors = ["justinsoong <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)