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

Add Consumer.exceptions property for handling client exceptions #117

Merged
merged 12 commits into from
Oct 23, 2018

Conversation

prkumar
Copy link
Owner

@prkumar prkumar commented Oct 20, 2018

Fixes #57.

Each Consumer instance has an exceptions property that exposes an enum of standard HTTP client exceptions that can be handled:

try:
    repo = github.create_repo(name="myproject", auto_init=True)
except github.exceptions.ConnectionError:
    # Handle client socket error:
    ...

This approach to handling exceptions decouples your code from the backing HTTP client, improving code reuse and testability.

Here are the HTTP client exceptions that are exposed through this property:

  • BaseClientException: Base exception for client connection errors.
  • ConnectionError: A client socket error occurred.
  • ConnectionTimeout: The request timed out while trying to connect to the remote server.
  • ServerTimeout: The server did not send any data in the allotted amount of time.
  • SSLError: An SSL error occurred.
  • InvalidURL: URL used for fetching is malformed.

Of course, you can also explicitly catch a particular client error from the backing client (e.g., requests.FileModeWarning). This may be useful for handling exceptions that are not exposed through the Consumer.exceptions property, for example:

try:
    repo = github.create_repo(name="myproject", auto_init=True)
except aiohttp.ContentTypeError:
    ...

FYI: @daa

@codecov
Copy link

codecov bot commented Oct 20, 2018

Codecov Report

Merging #117 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #117   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          25     25           
  Lines        1395   1410   +15     
  Branches      131    131           
=====================================
+ Hits         1395   1410   +15
Impacted Files Coverage Δ
uplink/builder.py 100% <100%> (ø) ⬆️
uplink/clients/aiohttp_.py 100% <100%> (ø) ⬆️
uplink/clients/requests_.py 100% <100%> (ø) ⬆️
uplink/clients/exceptions.py 100% <100%> (ø)
uplink/exceptions.py

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7ece240...25c8b95. Read the comment docs.

@prkumar prkumar merged commit 82806c1 into master Oct 23, 2018
@prkumar prkumar deleted the feature/v0.7.0/client-exceptions branch October 24, 2018 22:18
@prkumar prkumar mentioned this pull request Dec 7, 2018
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.

None yet

1 participant