Skip to content
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

Raise HTTP/JSON/API errors as exceptions #19

Merged
merged 4 commits into from
May 25, 2017

Conversation

kizzard
Copy link
Contributor

@kizzard kizzard commented May 25, 2017

Raise errors as exceptions

Type: Feature
Description: Raise HTTP/JSON/API errors as exceptions in order to make it more obvious what is going wrong. Related to #8

Implemented for methods:

  • request_devices
  • request_endpoints
  • device_request

Handles:

  • HTTP Status code errors
  • Invalid JSON responses
  • API errors received in JSON

Methodology:

  1. Check if JSON can be decoded. If not:
    • Check for HTTP status code errors
    • Otherwise raise generic invalid JSON error (except for device_request, as blank response indicates success)
  2. Check for API error in JSON response
    • JSON Errors come in two flavors, so method handles both types

Appendix:

API Error formats observed / handled:

  1. {"error":true,"type":"{type}","message":"{message}"}
  2. {"error":"{type}","error_description":"{message}"}

@dpjanes
Copy link
Owner

dpjanes commented May 25, 2017

Can you make one change: jsonResponse -> json_response

@kizzard
Copy link
Contributor Author

kizzard commented May 25, 2017

Done! Also changed errorType and errorMessage to use underscores too.

@dpjanes dpjanes merged commit dec37a8 into dpjanes:master May 25, 2017
@dpjanes
Copy link
Owner

dpjanes commented May 25, 2017

Cheers!

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.

2 participants