Skip to content

Commit 722c39c

Browse files
committed
Support specific ConflictException.
1 parent e4645ff commit 722c39c

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

tests/test_sync_http_client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
AuthorizationException,
1010
BadRequestException,
1111
BaseRequestException,
12+
ConflictException,
1213
ServerException,
1314
)
1415
from workos.utils.http_client import SyncHTTPClient
@@ -251,6 +252,23 @@ def test_request_bad_body_raises_expected_exception_with_request_data(self):
251252
# This'll fail for sure here but... just using the nice error that'd come up
252253
assert ex.__class__ == ServerException
253254

255+
def test_conflict_exception(self):
256+
request_id = "request-123"
257+
258+
self.http_client._client.request = MagicMock(
259+
return_value=httpx.Response(
260+
status_code=409,
261+
headers={"X-Request-ID": request_id},
262+
),
263+
)
264+
265+
try:
266+
self.http_client.request("bad_place")
267+
except ConflictException as ex:
268+
assert str(ex) == "(message=No message, request_id=request-123)"
269+
except Exception as ex:
270+
assert ex.__class__ == ConflictException
271+
254272
def test_request_includes_base_headers(self, capture_and_mock_http_client_request):
255273
request_kwargs = capture_and_mock_http_client_request(self.http_client, {}, 200)
256274

workos/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ class BadRequestException(BaseRequestException):
5353
pass
5454

5555

56+
class ConflictException(BaseRequestException):
57+
pass
58+
59+
5660
class NotFoundException(BaseRequestException):
5761
pass
5862

workos/utils/_base_http_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from httpx._types import QueryParamTypes
1717

1818
from workos.exceptions import (
19+
ConflictException,
1920
ServerException,
2021
AuthenticationException,
2122
AuthorizationException,
@@ -101,6 +102,8 @@ def _maybe_raise_error_by_status_code(
101102
raise AuthorizationException(response, response_json)
102103
elif status_code == 404:
103104
raise NotFoundException(response, response_json)
105+
elif status_code == 409:
106+
raise ConflictException(response, response_json)
104107

105108
raise BadRequestException(response, response_json)
106109
elif status_code >= 500 and status_code < 600:

0 commit comments

Comments
 (0)