Skip to content

Commit 869e940

Browse files
committed
refactor: drop pydantic, support blocking and raise errors
1 parent a4b2d16 commit 869e940

File tree

5 files changed

+450
-370
lines changed

5 files changed

+450
-370
lines changed

gel/auth/__init__.py

+14
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,17 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717
#
18+
19+
from . import email_password
20+
from .common import BaseServerError, TokenData
21+
from .pkce import PKCE, generate_pkce, AsyncPKCE, generate_async_pkce
22+
23+
__all__ = [
24+
"email_password",
25+
"BaseServerError",
26+
"TokenData",
27+
"PKCE",
28+
"generate_pkce",
29+
"AsyncPKCE",
30+
"generate_async_pkce",
31+
]

gel/auth/token_data.py gel/auth/common.py

+30-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,42 @@
1717
#
1818

1919
from __future__ import annotations
20-
from typing import Optional
20+
from typing import Any, Optional
2121

22+
import dataclasses
2223
import uuid
2324

24-
from pydantic import BaseModel
25+
import httpx
2526

2627

27-
class TokenData(BaseModel):
28+
@dataclasses.dataclass
29+
class TokenData:
2830
auth_token: str
2931
identity_id: uuid.UUID
3032
provider_token: Optional[str]
3133
provider_refresh_token: Optional[str]
34+
35+
36+
@dataclasses.dataclass
37+
class BaseServerError(Exception):
38+
status_code: int
39+
message: str
40+
41+
@classmethod
42+
def raise_or_json(cls, response: httpx.Response, **kwargs) -> Any:
43+
try:
44+
response.raise_for_status()
45+
except httpx.HTTPStatusError as e:
46+
raise cls(
47+
status_code=e.response.status_code,
48+
message=e.response.text,
49+
**kwargs,
50+
)
51+
json = response.json()
52+
if "error" in json:
53+
raise cls(
54+
status_code=response.status_code,
55+
message=json["error"],
56+
**kwargs,
57+
)
58+
return json

0 commit comments

Comments
 (0)