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

Pass the consumer instance to error and response handlers #118

Merged
merged 10 commits into from
Oct 30, 2018

Conversation

prkumar
Copy link
Owner

@prkumar prkumar commented Oct 27, 2018

The @error_handler and @response_handler decorators registers callbacks for users to perform specific follow-up operations on success and error cases.

In this PR, both decorators now support the optional argument requires_consumer. When this option is set to True, the registered callback should accept a reference to the Consumer
instance as its leading argument:

@error_handler(requires_consumer=True)
def raise_api_error(consumer, exc_type, exc_val, exc_tb):
     """Wraps client error with custom API error"""
        ...

class GitHub(Consumer):
    @raise_api_error
    @post("user/repo")
    def create_repo(self, name: Field):
        """Create a new repository."""

This adds value to other features, like #117.

@prkumar prkumar added this to the v0.7.0 milestone Oct 27, 2018
@codecov
Copy link

codecov bot commented Oct 27, 2018

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #118   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          25     25           
  Lines        1405   1419   +14     
  Branches      131    134    +3     
=====================================
+ Hits         1405   1419   +14
Impacted Files Coverage Δ
uplink/builder.py 100% <100%> (ø) ⬆️
uplink/decorators.py 100% <100%> (ø) ⬆️
uplink/session.py 100% <100%> (ø) ⬆️
uplink/hooks.py 100% <100%> (ø) ⬆️

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 d5b1d37...eb461e9. Read the comment docs.

@prkumar prkumar merged commit f92956f into master Oct 30, 2018
@prkumar prkumar deleted the feature/v0.7.0/pass-consumer-through branch October 30, 2018 19:55
@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.

1 participant