Skip to content

Simplify ApiError messages and add data attributes #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 3, 2019

Conversation

cmlccie
Copy link
Collaborator

@cmlccie cmlccie commented Jan 3, 2019

Per issue #62: Simplify 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 inspection:

  • response - The requests.Response object returned from the API call.
  • request - The requests.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.

This enhancement also solves issue #68.

Python 2 `json` module doesn't have a `JSONDecodeError`.  **ugh**

Fortunately `JSONDecodeError` is a subclass of `ValueError`, so we can use this to catch the same parsing error in both Python 2 and 3.
@cmlccie cmlccie merged commit 719b586 into master Jan 3, 2019
@cmlccie cmlccie deleted the enhance-exceptions branch January 3, 2019 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant