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

Fixes #42. Add 'raise_with' option #45

Merged
merged 1 commit into from
Aug 16, 2014

Conversation

prat0318
Copy link
Contributor

No description provided.

prat0318 added a commit that referenced this pull request Aug 16, 2014
@prat0318 prat0318 merged commit 02e186a into master Aug 16, 2014
@prat0318 prat0318 deleted the custom_exception_raise_option_issue44 branch August 22, 2014 20:10
@dnephin
Copy link
Contributor

dnephin commented Dec 27, 2014

This seems unrelated to issue #42.

What was the reason to add this? I'm doing some refactoring of SwaggerClient, and it seems like this functionality is unnecessary. If a consumer of swagger-py wants to customize the exception, they can always try/catch in their code.

I can't find any benefit to handling this code in swagger-py itself.

@prat0318
Copy link
Contributor Author

Yeah, it seems unrelated to #42. The only issue with client side try/catch is that all the request calls from a single client would have to be wrapped up separately each time. Adding it during client generation makes it one place declaration and less client code.

@prat0318
Copy link
Contributor Author

It actually fixes #44.

@dnephin
Copy link
Contributor

dnephin commented Dec 27, 2014

You can still do this without having to add code to swagger-py. A class decorator can wrap the entire client and handle these errors without any more code.

class ErrorHandler(object):

    def __init__(self, client, handler):
        self.client = client
        self.handler = handler

    def __getattr__(self, name):
        def operation(*args, **kwargs):
            try:
                return getattr(self.swagger_client, name)(*args, **kwargs)
            exception Exception as e:
                self.handler(name, e)

client = ErrorHandler(SwaggerClient(...), my_error_handler)

I would like to remove support for raise_with.

We could instead provide a factory to build a decorator like this from a callable

@dnephin
Copy link
Contributor

dnephin commented Dec 27, 2014

I'll create a new issue

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

2 participants