Repository navigation
Expand file tree
/
Copy patherrorresponse.py
More file actions
67 lines (51 loc) · 1.92 KB
/
Copy patherrorresponse.py
File metadata and controls
67 lines (51 loc) · 1.92 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
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from cloudinary_account_provisioning.models import CloudinaryError
from cloudinary_account_provisioning.types import (
BaseModel,
UNSET_SENTINEL,
current_exclude_none,
serialize_with_info,
)
from dataclasses import dataclass, field
import httpx
from pydantic import model_serializer
from typing import Optional
from typing_extensions import NotRequired, TypedDict
class ErrorTypedDict(TypedDict):
message: NotRequired[str]
class Error(BaseModel):
message: Optional[str] = None
@model_serializer(mode="wrap")
def _serialize_model_with_info(self, handler, info):
return serialize_with_info(self.serialize_model, handler, info)
def serialize_model(self, handler):
optional_fields = set(["message"])
exclude_none = current_exclude_none()
serialized = handler(self)
m = {}
for n, f in type(self).model_fields.items():
k = f.alias if f.alias is not None else n
if k not in serialized and n not in serialized and exclude_none is False:
continue
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 ErrorResponseData(BaseModel):
error: Optional[Error] = None
@dataclass(unsafe_hash=True)
class ErrorResponse(CloudinaryError):
r"""Bad request."""
data: ErrorResponseData = field(hash=False)
def __init__(
self,
data: ErrorResponseData,
raw_response: httpx.Response,
body: Optional[str] = None,
):
fallback = body or raw_response.text
message = str(data.error.message) if data.error else fallback
super().__init__(message, raw_response, body)
object.__setattr__(self, "data", data)