-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy patherrors.py
More file actions
31 lines (23 loc) · 1008 Bytes
/
errors.py
File metadata and controls
31 lines (23 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import httpx
from clerk import types
__all__ = ["ClerkAPIException", "NoActiveSessionException"]
class ClerkAPIException(Exception):
def __init__(self, status: int, data: str, url: str, *api_errors: types.Error) -> None:
self.status_code = status
self.data = data
self.url = url
self.api_errors = api_errors
super().__init__(f"{self.url}: {self.status_code} {self.api_errors!r}")
@classmethod
async def from_response(cls, resp: httpx.Response) -> "ClerkAPIException":
try:
data = resp.json()
except: # noqa
api_errors = []
else:
errors = data.get("errors", [])
api_errors = [types.Error.model_validate(e) for e in errors]
return ClerkAPIException(resp.status_code, resp.content, str(resp.url), *api_errors)
class NoActiveSessionException(Exception):
def __init__(self, client_id: str):
super().__init__(f"no active sessions for given client {client_id}")