Debian Codegraph @

src/auth0/management/jobs/errors/raw_client.py

raw symbols SCIP
1 # This file was auto-generated by Fern from our API Definition.
2
3 import typing
4 from json.decoder import JSONDecodeError
5
6 from ...core.api_error import ApiError
7 from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
8 from ...core.http_response import AsyncHttpResponse, HttpResponse
9 from ...core.jsonable_encoder import encode_path_param
10 from ...core.parse_error import ParsingError
11 from ...core.pydantic_utilities import parse_obj_as
12 from ...core.request_options import RequestOptions
13 from ...errors.bad_request_error import BadRequestError
14 from ...errors.forbidden_error import ForbiddenError
15 from ...errors.not_found_error import NotFoundError
16 from ...errors.too_many_requests_error import TooManyRequestsError
17 from ...errors.unauthorized_error import UnauthorizedError
18 from .types.errors_get_response import ErrorsGetResponse
19 from pydantic import ValidationError
20
21
22 class RawErrorsClient:
23 def __init__(self, *, client_wrapper: SyncClientWrapper):
24 self._client_wrapper = client_wrapper
25
26 def get(
27 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
28 ) -> HttpResponse[typing.Optional[ErrorsGetResponse]]:
29 """
30 Retrieve error details of a failed job.
31
32 Parameters
33 ----------
34 id : str
35 ID of the job.
36
37 request_options : typing.Optional[RequestOptions]
38 Request-specific configuration.
39
40 Returns
41 -------
42 HttpResponse[typing.Optional[ErrorsGetResponse]]
43 Job successfully retrieved.
44 """
45 _response = self._client_wrapper.httpx_client.request(
46 f"jobs/{encode_path_param(id)}/errors",
47 method="GET",
48 request_options=request_options,
49 )
50 try:
51 if _response is None or not _response.text.strip():
52 return HttpResponse(response=_response, data=None)
53 if 200 <= _response.status_code < 300:
54 _data = typing.cast(
55 typing.Optional[ErrorsGetResponse],
56 parse_obj_as(
57 type_=typing.Optional[ErrorsGetResponse], # type: ignore
58 object_=_response.json(),
59 ),
60 )
61 return HttpResponse(response=_response, data=_data)
62 if _response.status_code == 400:
63 raise BadRequestError(
64 headers=dict(_response.headers),
65 body=typing.cast(
66 typing.Any,
67 parse_obj_as(
68 type_=typing.Any, # type: ignore
69 object_=_response.json(),
70 ),
71 ),
72 )
73 if _response.status_code == 401:
74 raise UnauthorizedError(
75 headers=dict(_response.headers),
76 body=typing.cast(
77 typing.Any,
78 parse_obj_as(
79 type_=typing.Any, # type: ignore
80 object_=_response.json(),
81 ),
82 ),
83 )
84 if _response.status_code == 403:
85 raise ForbiddenError(
86 headers=dict(_response.headers),
87 body=typing.cast(
88 typing.Any,
89 parse_obj_as(
90 type_=typing.Any, # type: ignore
91 object_=_response.json(),
92 ),
93 ),
94 )
95 if _response.status_code == 404:
96 raise NotFoundError(
97 headers=dict(_response.headers),
98 body=typing.cast(
99 typing.Any,
100 parse_obj_as(
101 type_=typing.Any, # type: ignore
102 object_=_response.json(),
103 ),
104 ),
105 )
106 if _response.status_code == 429:
107 raise TooManyRequestsError(
108 headers=dict(_response.headers),
109 body=typing.cast(
110 typing.Any,
111 parse_obj_as(
112 type_=typing.Any, # type: ignore
113 object_=_response.json(),
114 ),
115 ),
116 )
117 _response_json = _response.json()
118 except JSONDecodeError:
119 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
120 except ValidationError as e:
121 raise ParsingError(
122 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
123 )
124 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
125
126
127 class AsyncRawErrorsClient:
128 def __init__(self, *, client_wrapper: AsyncClientWrapper):
129 self._client_wrapper = client_wrapper
130
131 async def get(
132 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
133 ) -> AsyncHttpResponse[typing.Optional[ErrorsGetResponse]]:
134 """
135 Retrieve error details of a failed job.
136
137 Parameters
138 ----------
139 id : str
140 ID of the job.
141
142 request_options : typing.Optional[RequestOptions]
143 Request-specific configuration.
144
145 Returns
146 -------
147 AsyncHttpResponse[typing.Optional[ErrorsGetResponse]]
148 Job successfully retrieved.
149 """
150 _response = await self._client_wrapper.httpx_client.request(
151 f"jobs/{encode_path_param(id)}/errors",
152 method="GET",
153 request_options=request_options,
154 )
155 try:
156 if _response is None or not _response.text.strip():
157 return AsyncHttpResponse(response=_response, data=None)
158 if 200 <= _response.status_code < 300:
159 _data = typing.cast(
160 typing.Optional[ErrorsGetResponse],
161 parse_obj_as(
162 type_=typing.Optional[ErrorsGetResponse], # type: ignore
163 object_=_response.json(),
164 ),
165 )
166 return AsyncHttpResponse(response=_response, data=_data)
167 if _response.status_code == 400:
168 raise BadRequestError(
169 headers=dict(_response.headers),
170 body=typing.cast(
171 typing.Any,
172 parse_obj_as(
173 type_=typing.Any, # type: ignore
174 object_=_response.json(),
175 ),
176 ),
177 )
178 if _response.status_code == 401:
179 raise UnauthorizedError(
180 headers=dict(_response.headers),
181 body=typing.cast(
182 typing.Any,
183 parse_obj_as(
184 type_=typing.Any, # type: ignore
185 object_=_response.json(),
186 ),
187 ),
188 )
189 if _response.status_code == 403:
190 raise ForbiddenError(
191 headers=dict(_response.headers),
192 body=typing.cast(
193 typing.Any,
194 parse_obj_as(
195 type_=typing.Any, # type: ignore
196 object_=_response.json(),
197 ),
198 ),
199 )
200 if _response.status_code == 404:
201 raise NotFoundError(
202 headers=dict(_response.headers),
203 body=typing.cast(
204 typing.Any,
205 parse_obj_as(
206 type_=typing.Any, # type: ignore
207 object_=_response.json(),
208 ),
209 ),
210 )
211 if _response.status_code == 429:
212 raise TooManyRequestsError(
213 headers=dict(_response.headers),
214 body=typing.cast(
215 typing.Any,
216 parse_obj_as(
217 type_=typing.Any, # type: ignore
218 object_=_response.json(),
219 ),
220 ),
221 )
222 _response_json = _response.json()
223 except JSONDecodeError:
224 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
225 except ValidationError as e:
226 raise ParsingError(
227 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
228 )
229 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)