Reference for hub_sdk/helpers/error_handler.py
Note
This file is available at https://github.com/ultralytics/hub-sdk/blob/main/hub_sdk/helpers/error_handler.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
hub_sdk.helpers.error_handler.ErrorHandler
ErrorHandler(
status_code: int,
message: Optional[str] = None,
headers: Optional[dict] = None,
)
Represents an error handler for managing HTTP status codes and error messages.
Attributes:
Name | Type | Description |
---|---|---|
status_code |
int
|
The HTTP status code associated with the error. |
message |
str | None
|
An optional error message providing additional details. |
headers |
dict | None
|
An optional dictionary providing response headers details. |
Methods:
Name | Description |
---|---|
handle |
Handle the error based on the provided status code. |
handle_unauthorized |
Handle an unauthorized error (HTTP 401). |
handle_ratelimit_exceeded |
Handle rate limit exceeded error (HTTP 429). |
handle_not_found |
Handle a resource not found error (HTTP 404). |
handle_internal_server_error |
Handle an internal server error (HTTP 500). |
handle_unknown_error |
Handle an unknown error. |
get_default_message |
Get the default error message for a given HTTP status code. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
status_code
|
int
|
The HTTP status code representing the error. |
required |
message
|
str
|
An optional error message providing additional details. |
None
|
headers
|
dict
|
An optional dictionary providing response headers details. |
None
|
Source code in hub_sdk/helpers/error_handler.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
get_default_message
get_default_message() -> str
Get the default error message for a given HTTP status code.
Returns:
Type | Description |
---|---|
str
|
The default error message associated with the provided status code or unknown error message if not found. |
Source code in hub_sdk/helpers/error_handler.py
125 126 127 128 129 130 131 132 |
|
handle
handle() -> str
Handle the error based on the provided status code.
Returns:
Type | Description |
---|---|
str
|
A message describing the error. |
Source code in hub_sdk/helpers/error_handler.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
handle_internal_server_error
staticmethod
handle_internal_server_error() -> str
Handle an internal server error (HTTP 500).
Returns:
Type | Description |
---|---|
str
|
An error message indicating an internal server error. |
Source code in hub_sdk/helpers/error_handler.py
105 106 107 108 109 110 111 112 113 |
|
handle_not_found
staticmethod
handle_not_found() -> str
Handle a resource not found error (HTTP 404).
Returns:
Type | Description |
---|---|
str
|
An error message indicating that the requested resource was not found. |
Source code in hub_sdk/helpers/error_handler.py
95 96 97 98 99 100 101 102 103 |
|
handle_ratelimit_exceeded
handle_ratelimit_exceeded() -> str
Handle rate limit exceeded error (HTTP 429).
Returns:
Type | Description |
---|---|
str
|
An error message indicating rate limit exceeded with reset time if available. |
Source code in hub_sdk/helpers/error_handler.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
handle_unauthorized
staticmethod
handle_unauthorized() -> str
Handle an unauthorized error (HTTP 401).
Returns:
Type | Description |
---|---|
str
|
An error message indicating unauthorized access. |
Source code in hub_sdk/helpers/error_handler.py
62 63 64 65 66 67 68 69 70 |
|
handle_unknown_error
staticmethod
handle_unknown_error() -> str
Handle an unknown error.
Returns:
Type | Description |
---|---|
str
|
An error message indicating that an unknown error occurred. |
Source code in hub_sdk/helpers/error_handler.py
115 116 117 118 119 120 121 122 123 |
|