Skip to content

Commit 7b64c85

Browse files
committed
fix(client): include more detail in error messages (#12)
1 parent 4dab0a6 commit 7b64c85

File tree

1 file changed

+22
-33
lines changed

1 file changed

+22
-33
lines changed

src/orb/_exceptions.py

+22-33
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,12 @@ class DuplicateResourceCreation(BadRequestError):
132132

133133
def __init__(self, message: str, *, body: object, response: httpx.Response) -> None:
134134
data = cast(Mapping[str, object], body if is_mapping(body) else {})
135-
title = cast(Any, data.get("title"))
136-
super().__init__(title or message, response=response, body=body)
135+
super().__init__(message, response=response, body=body)
137136

138-
self.title = title
139137
self.status = cast(Any, data.get("status"))
140138
self.type = cast(Any, data.get("type"))
141139
self.detail = cast(Any, data.get("detail"))
140+
self.title = cast(Any, data.get("title"))
142141

143142

144143
class FeatureNotAvailable(BadRequestError):
@@ -152,13 +151,12 @@ class FeatureNotAvailable(BadRequestError):
152151

153152
def __init__(self, message: str, *, body: object, response: httpx.Response) -> None:
154153
data = cast(Mapping[str, object], body if is_mapping(body) else {})
155-
title = cast(Any, data.get("title"))
156-
super().__init__(title or message, response=response, body=body)
154+
super().__init__(message, response=response, body=body)
157155

158-
self.title = title
159156
self.status = cast(Any, data.get("status"))
160157
self.type = cast(Any, data.get("type"))
161158
self.detail = cast(Any, data.get("detail"))
159+
self.title = cast(Any, data.get("title"))
162160

163161

164162
class RequestValidationError(BadRequestError):
@@ -174,14 +172,13 @@ class RequestValidationError(BadRequestError):
174172

175173
def __init__(self, message: str, *, body: object, response: httpx.Response) -> None:
176174
data = cast(Mapping[str, object], body if is_mapping(body) else {})
177-
title = cast(Any, data.get("title"))
178-
super().__init__(title or message, response=response, body=body)
175+
super().__init__(message, response=response, body=body)
179176

180-
self.title = title
181177
self.status = cast(Any, data.get("status"))
182178
self.type = cast(Any, data.get("type"))
183179
self.validation_errors = cast(Any, data.get("validation_errors"))
184180
self.detail = cast(Any, data.get("detail"))
181+
self.title = cast(Any, data.get("title"))
185182

186183

187184
class OrbAuthenticationError(AuthenticationError):
@@ -195,13 +192,12 @@ class OrbAuthenticationError(AuthenticationError):
195192

196193
def __init__(self, message: str, *, body: object, response: httpx.Response) -> None:
197194
data = cast(Mapping[str, object], body if is_mapping(body) else {})
198-
title = cast(Any, data.get("title"))
199-
super().__init__(title or message, response=response, body=body)
195+
super().__init__(message, response=response, body=body)
200196

201-
self.title = title
202197
self.status = cast(Any, data.get("status"))
203198
self.type = cast(Any, data.get("type"))
204199
self.detail = cast(Any, data.get("detail"))
200+
self.title = cast(Any, data.get("title"))
205201

206202

207203
class ResourceNotFound(NotFoundError):
@@ -215,11 +211,10 @@ class ResourceNotFound(NotFoundError):
215211

216212
def __init__(self, message: str, *, body: object, response: httpx.Response) -> None:
217213
data = cast(Mapping[str, object], body if is_mapping(body) else {})
218-
title = cast(Any, data.get("title"))
219-
super().__init__(title or message, response=response, body=body)
214+
super().__init__(message, response=response, body=body)
220215

221-
self.title = title
222216
self.status = cast(Any, data.get("status"))
217+
self.title = cast(Any, data.get("title"))
223218
self.type = cast(Any, data.get("type"))
224219
self.detail = cast(Any, data.get("detail"))
225220

@@ -235,13 +230,12 @@ class URLNotFound(NotFoundError):
235230

236231
def __init__(self, message: str, *, body: object, response: httpx.Response) -> None:
237232
data = cast(Mapping[str, object], body if is_mapping(body) else {})
238-
title = cast(Any, data.get("title"))
239-
super().__init__(title or message, response=response, body=body)
233+
super().__init__(message, response=response, body=body)
240234

241-
self.title = title
242235
self.status = cast(Any, data.get("status"))
243236
self.type = cast(Any, data.get("type"))
244237
self.detail = cast(Any, data.get("detail"))
238+
self.title = cast(Any, data.get("title"))
245239

246240

247241
class ResourceConflict(ConflictError):
@@ -255,13 +249,12 @@ class ResourceConflict(ConflictError):
255249

256250
def __init__(self, message: str, *, body: object, response: httpx.Response) -> None:
257251
data = cast(Mapping[str, object], body if is_mapping(body) else {})
258-
title = cast(Any, data.get("title"))
259-
super().__init__(title or message, response=response, body=body)
252+
super().__init__(message, response=response, body=body)
260253

261-
self.title = title
262254
self.status = cast(Any, data.get("status"))
263255
self.type = cast(Any, data.get("type"))
264256
self.detail = cast(Any, data.get("detail"))
257+
self.title = cast(Any, data.get("title"))
265258

266259

267260
class RequestTooLarge(APIStatusError):
@@ -275,13 +268,12 @@ class RequestTooLarge(APIStatusError):
275268

276269
def __init__(self, message: str, *, body: object, response: httpx.Response) -> None:
277270
data = cast(Mapping[str, object], body if is_mapping(body) else {})
278-
title = cast(Any, data.get("title"))
279-
super().__init__(title or message, response=response, body=body)
271+
super().__init__(message, response=response, body=body)
280272

281-
self.title = title
282273
self.status = cast(Any, data.get("status"))
283274
self.type = cast(Any, data.get("type"))
284275
self.detail = cast(Any, data.get("detail"))
276+
self.title = cast(Any, data.get("title"))
285277

286278

287279
class ResourceTooLarge(APIStatusError):
@@ -295,13 +287,12 @@ class ResourceTooLarge(APIStatusError):
295287

296288
def __init__(self, message: str, *, body: object, response: httpx.Response) -> None:
297289
data = cast(Mapping[str, object], body if is_mapping(body) else {})
298-
title = cast(Any, data.get("title"))
299-
super().__init__(title or message, response=response, body=body)
290+
super().__init__(message, response=response, body=body)
300291

301-
self.title = title
302292
self.status = cast(Any, data.get("status"))
303293
self.type = cast(Any, data.get("type"))
304294
self.detail = cast(Any, data.get("detail"))
295+
self.title = cast(Any, data.get("title"))
305296

306297

307298
class TooManyRequests(RateLimitError):
@@ -315,13 +306,12 @@ class TooManyRequests(RateLimitError):
315306

316307
def __init__(self, message: str, *, body: object, response: httpx.Response) -> None:
317308
data = cast(Mapping[str, object], body if is_mapping(body) else {})
318-
title = cast(Any, data.get("title"))
319-
super().__init__(title or message, response=response, body=body)
309+
super().__init__(message, response=response, body=body)
320310

321-
self.title = title
322311
self.status = cast(Any, data.get("status"))
323312
self.type = cast(Any, data.get("type"))
324313
self.detail = cast(Any, data.get("detail"))
314+
self.title = cast(Any, data.get("title"))
325315

326316

327317
class OrbInternalServerError(InternalServerError):
@@ -335,10 +325,9 @@ class OrbInternalServerError(InternalServerError):
335325

336326
def __init__(self, message: str, *, body: object, response: httpx.Response) -> None:
337327
data = cast(Mapping[str, object], body if is_mapping(body) else {})
338-
title = cast(Any, data.get("title"))
339-
super().__init__(title or message, response=response, body=body)
328+
super().__init__(message, response=response, body=body)
340329

341-
self.title = title
342330
self.status = cast(Any, data.get("status"))
343331
self.type = cast(Any, data.get("type"))
344332
self.detail = cast(Any, data.get("detail"))
333+
self.title = cast(Any, data.get("title"))

0 commit comments

Comments
 (0)