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 responses appropriately to errors (swaggerpy) #158

Merged
merged 1 commit into from
Jul 7, 2015

Conversation

bpicolo
Copy link
Contributor

@bpicolo bpicolo commented Jul 7, 2015

Fixes #156 , the main issue being that we actually weren't passing responses to exceptions properly.

e.json might make a good convenience method, but I skipped it for now (e.response.json is a good substitute. But documenting this at some point would be good)

@bpicolo bpicolo changed the title Pass responses appropriately to errors Pass responses appropriately to errors (swaggerpy) Jul 7, 2015
@@ -26,9 +26,13 @@ def handle_response_errors(e):
:raises HTTPError: :class: `swaggerpy.exception.HTTPError`
"""
args = list(e.args)
kwargs = {}
if hasattr(e, 'response') and hasattr(e.response, 'text'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there value in setting kwargs['response'] even though e.response.text doesn't exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, yeah, definitely. fixed

@bpicolo bpicolo force-pushed the support_json_error_responses branch from 8d07f5d to e35602d Compare July 7, 2015 20:44
try:
handle_response_errors(error)
except HTTPError as e:
self.assertEqual(e.json, {'foo': 'bar'})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is e.json getting set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that was from previous diff where I had added that as a property to exception. Fixed <3

@analogue
Copy link
Contributor

analogue commented Jul 7, 2015

lgtm

would be good to have @prat0318 give it a once over since he is more familiar with the codebase.

@bpicolo bpicolo force-pushed the support_json_error_responses branch from e35602d to 8b56705 Compare July 7, 2015 21:06
@bpicolo bpicolo added the bug label Jul 7, 2015
except HTTPError as e:
self.assertEqual(e.response.json(), {'foo': 'bar'})
self.assertEqual(e.response, response)
self.assertEqual(e.request, request)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if there is a test already that '400 Bad Request' is contained in the e's args, will be good to add it if not present already.

@prat0318
Copy link
Contributor

prat0318 commented Jul 7, 2015

lgtm

analogue added a commit that referenced this pull request Jul 7, 2015
Pass responses appropriately to errors (swaggerpy)
@analogue analogue merged commit 13bb636 into Yelp:swaggerpy Jul 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants