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

request: full response object in status code exception #85

Open
dsayling opened this issue Nov 22, 2022 · 0 comments
Open

request: full response object in status code exception #85

dsayling opened this issue Nov 22, 2022 · 0 comments

Comments

@dsayling
Copy link
Contributor

I was wondering if it be ok to include the full response object in the exception along with the args currently there? The response has the headers, and request, which can make logging failures easier. It also might be nice to include some attributes on the exception.

class StatusCodeError(TestRailAPIError):
    def __init__(self, *args, **kwargs):
        super().__init__(*args)
        self.status_code = args[0]
        self.reason = args[1]
        self.url = args[2]
        self.content = args[3]
        self.response = kwargs.get('response')

existing args access still works, but you'd have attributes to hand onto.

>>> e = StatusCodeError(500, "bad", "url", "content", response={'a':1})
>>> e.args[0]
500
>>> e.status_code
500
>>> e.response
{'a': 1}
>>> raise e
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StatusCodeError: (500, 'bad', 'url', 'content')
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

No branches or pull requests

1 participant