-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorresponse.py
More file actions
56 lines (41 loc) · 1.53 KB
/
errorresponse.py
File metadata and controls
56 lines (41 loc) · 1.53 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
"""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
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(self, handler):
optional_fields = set(["message"])
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 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)