You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`.raw_response`|*httpx.Response*| The raw HTTP response |
357
-
|`.body`|*str*| The response content |
358
-
359
-
When custom error responses are specified for an operation, the SDK may also raise their associated exceptions. You can refer to respective *Errors* tables in SDK docs for more details on possible exception types for each operation. For example, the `create_async` method may raise the following exceptions:
|`err.body`|`str`| HTTP body. Can be empty string if no body is returned. |
356
+
|`err.raw_response`|`httpx.Response`| Raw HTTP response |
357
+
|`err.data`|| Optional. Some errors may contain structured data. [See Error Classes](#error-classes). |
375
358
359
+
### Example
376
360
```python
377
361
from dub import Dub
378
362
from dub.models import errors
@@ -407,37 +391,47 @@ with Dub(
407
391
# Handle response
408
392
print(res)
409
393
410
-
except errors.BadRequest as e:
411
-
# handle e.data: errors.BadRequestData
412
-
raise(e)
413
-
except errors.Unauthorized as e:
414
-
# handle e.data: errors.UnauthorizedData
415
-
raise(e)
416
-
except errors.Forbidden as e:
417
-
# handle e.data: errors.ForbiddenData
418
-
raise(e)
419
-
except errors.NotFound as e:
420
-
# handle e.data: errors.NotFoundData
421
-
raise(e)
422
-
except errors.Conflict as e:
423
-
# handle e.data: errors.ConflictData
424
-
raise(e)
425
-
except errors.InviteExpired as e:
426
-
# handle e.data: errors.InviteExpiredData
427
-
raise(e)
428
-
except errors.UnprocessableEntity as e:
429
-
# handle e.data: errors.UnprocessableEntityData
430
-
raise(e)
431
-
except errors.RateLimitExceeded as e:
432
-
# handle e.data: errors.RateLimitExceededData
433
-
raise(e)
434
-
except errors.InternalServerError as e:
435
-
# handle e.data: errors.InternalServerErrorData
436
-
raise(e)
437
-
except errors.SDKError as e:
438
-
# handle exception
439
-
raise(e)
394
+
395
+
except errors.DubError as e:
396
+
# The base class for HTTP error responses
397
+
print(e.message)
398
+
print(e.status_code)
399
+
print(e.body)
400
+
print(e.headers)
401
+
print(e.raw_response)
402
+
403
+
# Depending on the method different errors may be thrown
404
+
ifisinstance(e, errors.BadRequest):
405
+
print(e.data.error) # errors.Error
440
406
```
407
+
408
+
### Error Classes
409
+
**Primary errors:**
410
+
*[`DubError`](./src/dub/models/errors/duberror.py): The base class for HTTP error responses.
411
+
*[`BadRequest`](./src/dub/models/errors/badrequest.py): 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). Status code `400`.
412
+
*[`Unauthorized`](./src/dub/models/errors/unauthorized.py): Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. Status code `401`.
413
+
*[`Forbidden`](./src/dub/models/errors/forbidden.py): The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. Status code `403`.
414
+
*[`NotFound`](./src/dub/models/errors/notfound.py): The server cannot find the requested resource. Status code `404`.
415
+
*[`Conflict`](./src/dub/models/errors/conflict.py): This response is sent when a request conflicts with the current state of the server. Status code `409`.
416
+
*[`InviteExpired`](./src/dub/models/errors/inviteexpired.py): This response is sent when the requested content has been permanently deleted from server, with no forwarding address. Status code `410`.
417
+
*[`UnprocessableEntity`](./src/dub/models/errors/unprocessableentity.py): The request was well-formed but was unable to be followed due to semantic errors. Status code `422`.
418
+
*[`RateLimitExceeded`](./src/dub/models/errors/ratelimitexceeded.py): The user has sent too many requests in a given amount of time ("rate limiting"). Status code `429`.
419
+
*[`InternalServerError`](./src/dub/models/errors/internalservererror.py): The server has encountered a situation it does not know how to handle. Status code `500`.
420
+
421
+
<details><summary>Less common errors (5)</summary>
422
+
423
+
<br />
424
+
425
+
**Network errors:**
426
+
*[`httpx.RequestError`](https://www.python-httpx.org/exceptions/#httpx.RequestError): Base class for request errors.
427
+
*[`httpx.ConnectError`](https://www.python-httpx.org/exceptions/#httpx.ConnectError): HTTP client was unable to make a request to a server.
**Inherit from [`DubError`](./src/dub/models/errors/duberror.py)**:
432
+
*[`ResponseValidationError`](./src/dub/models/errors/responsevalidationerror.py): Type mismatch between the response data and the expected Pydantic model. Provides access to the Pydantic validation error via the `cause` attribute.
0 commit comments