@@ -46,6 +46,11 @@ class webexteamssdkException(Exception):
4646 pass
4747
4848
49+ class webexteamssdkWarning (webexteamssdkException , Warning ):
50+ """Base class for all webexteamssdk warnings."""
51+ pass
52+
53+
4954class AccessTokenError (webexteamssdkException ):
5055 """Raised when an incorrect Webex Teams Access Token has been provided."""
5156 pass
@@ -73,6 +78,9 @@ def __init__(self, response):
7378 self .status = self .response .reason
7479 """The HTTP status from the API response."""
7580
81+ self .description = RESPONSE_CODES .get (self .status_code )
82+ """A description of the HTTP Response Code from the API docs."""
83+
7684 self .details = None
7785 """The parsed JSON details from the API response."""
7886 if "application/json" in \
@@ -85,24 +93,40 @@ def __init__(self, response):
8593 self .message = self .details .get ("message" ) if self .details else None
8694 """The error message from the parsed API response."""
8795
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."""
90101
91- super ( ApiError , self ). __init__ (
92- "[{status_code}]{status} - {message }" .format (
102+ self . error_message = (
103+ "[{status_code}]{status} - {detail}{tracking_id }" .format (
93104 status_code = self .status_code ,
94105 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 "" ,
96109 )
97110 )
98111
112+ super (ApiError , self ).__init__ (self .error_message )
113+
99114 def __repr__ (self ):
100- return "<{exception_name} [{status_code}]>" .format (
115+ return "<{exception_name} [{status_code}]{status} >" .format (
101116 exception_name = self .__class__ .__name__ ,
102117 status_code = self .status_code ,
118+ status = " " + self .status if self .status else "" ,
103119 )
104120
105121
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+
106130class RateLimitError (ApiError ):
107131 """Webex Teams Rate-Limit exceeded Error.
108132
@@ -125,26 +149,13 @@ def __init__(self, response):
125149 super (RateLimitError , self ).__init__ (response )
126150
127151
128- class RateLimitWarning (UserWarning ):
152+ class RateLimitWarning (ApiWarning , RateLimitError ):
129153 """Webex Teams rate-limit exceeded warning.
130154
131155 Raised when a rate-limit exceeded message is received and the request will
132156 be retried.
133157 """
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
148159
149160
150161class MalformedResponse (webexteamssdkException ):
0 commit comments