-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbadrequest.py
More file actions
75 lines (55 loc) · 2.2 KB
/
badrequest.py
File metadata and controls
75 lines (55 loc) · 2.2 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 Code(str, Enum):
r"""A short code indicating the error code returned."""
BAD_REQUEST = "bad_request"
class ErrorTypedDict(TypedDict):
code: Code
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 Error(BaseModel):
code: Code
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)
if val != UNSET_SENTINEL:
if val is not None or k not in optional_fields:
m[k] = val
return m
class BadRequestData(BaseModel):
error: Error
@dataclass(unsafe_hash=True)
class BadRequest(DubError):
r"""The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing)."""
data: BadRequestData = field(hash=False)
def __init__(
self,
data: BadRequestData,
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)