@@ -46,6 +46,11 @@ class webexteamssdkException(Exception):
46
46
pass
47
47
48
48
49
+ class webexteamssdkWarning (webexteamssdkException , Warning ):
50
+ """Base class for all webexteamssdk warnings."""
51
+ pass
52
+
53
+
49
54
class AccessTokenError (webexteamssdkException ):
50
55
"""Raised when an incorrect Webex Teams Access Token has been provided."""
51
56
pass
@@ -73,6 +78,9 @@ def __init__(self, response):
73
78
self .status = self .response .reason
74
79
"""The HTTP status from the API response."""
75
80
81
+ self .description = RESPONSE_CODES .get (self .status_code )
82
+ """A description of the HTTP Response Code from the API docs."""
83
+
76
84
self .details = None
77
85
"""The parsed JSON details from the API response."""
78
86
if "application/json" in \
@@ -85,24 +93,40 @@ def __init__(self, response):
85
93
self .message = self .details .get ("message" ) if self .details else None
86
94
"""The error message from the parsed API response."""
87
95
88
- self .description = RESPONSE_CODES .get (self .status_code )
89
- """A description of the HTTP Response Code from the API docs."""
96
+ self .tracking_id = (
97
+ self .details .get ("trackingId" ) if self .details else None
98
+ or self .response .headers .get ("trackingId" )
99
+ )
100
+ """The Webex Tracking ID from the response."""
90
101
91
- super ( ApiError , self ). __init__ (
92
- "[{status_code}]{status} - {message }" .format (
102
+ self . error_message = (
103
+ "[{status_code}]{status} - {detail}{tracking_id }" .format (
93
104
status_code = self .status_code ,
94
105
status = " " + self .status if self .status else "" ,
95
- message = self .message or self .description or "Unknown Error" ,
106
+ detail = self .message or self .description or "Unknown Error" ,
107
+ tracking_id = " [Tracking ID: " + self .tracking_id + "]"
108
+ if self .tracking_id else "" ,
96
109
)
97
110
)
98
111
112
+ super (ApiError , self ).__init__ (self .error_message )
113
+
99
114
def __repr__ (self ):
100
- return "<{exception_name} [{status_code}]>" .format (
115
+ return "<{exception_name} [{status_code}]{status} >" .format (
101
116
exception_name = self .__class__ .__name__ ,
102
117
status_code = self .status_code ,
118
+ status = " " + self .status if self .status else "" ,
103
119
)
104
120
105
121
122
+ class ApiWarning (webexteamssdkWarning , ApiError ):
123
+ """Warnings raised from API responses received from the Webex APIs.
124
+
125
+ Several data attributes are available for inspection.
126
+ """
127
+ pass
128
+
129
+
106
130
class RateLimitError (ApiError ):
107
131
"""Webex Teams Rate-Limit exceeded Error.
108
132
@@ -125,26 +149,13 @@ def __init__(self, response):
125
149
super (RateLimitError , self ).__init__ (response )
126
150
127
151
128
- class RateLimitWarning (UserWarning ):
152
+ class RateLimitWarning (ApiWarning , RateLimitError ):
129
153
"""Webex Teams rate-limit exceeded warning.
130
154
131
155
Raised when a rate-limit exceeded message is received and the request will
132
156
be retried.
133
157
"""
134
-
135
- def __init__ (self , response ):
136
- assert isinstance (response , requests .Response )
137
-
138
- # Extended warning attributes
139
- self .retry_after = max (1 , int (response .headers .get ('Retry-After' , 15 )))
140
- """The `Retry-After` time period (in seconds) provided by Webex Teams.
141
-
142
- Defaults to 15 seconds if the response `Retry-After` header isn't
143
- present in the response headers, and defaults to a minimum wait time of
144
- 1 second if Webex Teams returns a `Retry-After` header of 0 seconds.
145
- """
146
-
147
- super (RateLimitWarning , self ).__init__ ()
158
+ pass
148
159
149
160
150
161
class MalformedResponse (webexteamssdkException ):
0 commit comments