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
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. Defaults to None. |
headers |
(dict, None)
|
An optional dictionary providing response headers details. Defaults to None. |
Source code in hub_sdk/helpers/error_handler.py
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
__init__(status_code, message=None, headers=None)
Initialize the ErrorHandler object with a given 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, None)
|
An optional dictionary providing response headers details. |
None
|
Source code in hub_sdk/helpers/error_handler.py
get_default_message()
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. If no message is found, it falls back to handling an unknown error. |
Source code in hub_sdk/helpers/error_handler.py
handle()
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
handle_internal_server_error()
staticmethod
Handle an internal server error (HTTP 500).
Returns:
Type | Description |
---|---|
str
|
An error message indicating an internal server error. |
handle_not_found()
staticmethod
Handle a resource not found error (HTTP 404).
Returns:
Type | Description |
---|---|
str
|
An error message indicating that the requested resource was not found. |
handle_ratelimit_exceeded()
Handle rate limit exceeded error (HTTP 429).
Returns:
Type | Description |
---|---|
str
|
An error message indicating rate limit exceeded. |
Source code in hub_sdk/helpers/error_handler.py
handle_unauthorized()
staticmethod
Handle an unauthorized error (HTTP 401).
Returns:
Type | Description |
---|---|
str
|
An error message indicating unauthorized access. |
handle_unknown_error()
staticmethod
Handle an unknown error.
Returns:
Type | Description |
---|---|
str
|
An error message indicating that an unknown error occurred. |