Simplify ApiError Messages
ApiError
messages are now shorter, more insightful, and easier to inspect. 🙌
We have simplified the default string interpretation of the ApiError
messages. The simplified messages will use the message
attribute of the returned JSON (if present) to provide more insight as to why the request failed and will default to the generic error descriptions from the API docs if a message
attribute is not available.
Example of the New Message Format:
ApiError: [400] Bad Request - Message destination could not be determined. Provide only one destination in the roomId, toPersonEmail, or toPersonId field
The ApiError
exceptions now have several attributes exposed for easier inspection:
response
- Therequests.Response
object returned from the API call.request
- Therequests.PreparedRequest
used to submit the API request.status_code
- The HTTP status code from the API response.status
- The HTTP status from the API response.details
- The parsed JSON details from the API response.message
- The error message from the parsed API response.description
- A description of the HTTP Response Code from the API docs.
To inspect an error, simply catch it in a try block and access the above attributes on the caught error:
from webexteamssdk import ApiError, WebexTeamsAPI
api = WebexTeamsAPI()
try:
api.messages.create()
except ApiError as error:
print(error.message)
See ApiError
in the API Docs for more details.
This enhancement addresses enhancement request #62 and resolves 🐛 #68.