-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathunauthorized.py
More file actions
75 lines (55 loc) · 2.28 KB
/
unauthorized.py
File metadata and controls
75 lines (55 loc) · 2.28 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from dataclasses import dataclass, field
from dub.models.errors import DubError
from dub.types import BaseModel, UNSET_SENTINEL
from enum import Enum
import httpx
from pydantic import model_serializer
from typing import Optional
from typing_extensions import NotRequired, TypedDict
class UnauthorizedCode(str, Enum):
r"""A short code indicating the error code returned."""
UNAUTHORIZED = "unauthorized"
class UnauthorizedErrorTypedDict(TypedDict):
code: UnauthorizedCode
r"""A short code indicating the error code returned."""
message: str
r"""A human readable explanation of what went wrong."""
doc_url: NotRequired[str]
r"""A link to our documentation with more details about this error code"""
class UnauthorizedError(BaseModel):
code: UnauthorizedCode
r"""A short code indicating the error code returned."""
message: str
r"""A human readable explanation of what went wrong."""
doc_url: Optional[str] = None
r"""A link to our documentation with more details about this error code"""
@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = set(["doc_url"])
serialized = handler(self)
m = {}
for n, f in type(self).model_fields.items():
k = f.alias or n
val = serialized.get(k, serialized.get(n))
if val != UNSET_SENTINEL:
if val is not None or k not in optional_fields:
m[k] = val
return m
class UnauthorizedData(BaseModel):
error: UnauthorizedError
@dataclass(unsafe_hash=True)
class Unauthorized(DubError):
r"""Although the HTTP standard specifies \"unauthorized\", semantically this response means \"unauthenticated\". That is, the client must authenticate itself to get the requested response."""
data: UnauthorizedData = field(hash=False)
def __init__(
self,
data: UnauthorizedData,
raw_response: httpx.Response,
body: Optional[str] = None,
):
fallback = body or raw_response.text
message = str(data.error.message) or fallback
super().__init__(message, raw_response, body)
object.__setattr__(self, "data", data)