Repository navigation
Only attempt to parse JSON for JSON responses - #84
Conversation
| def __init__(self, content, status_code, headers=None): | ||
| self.content = content | ||
| self.status_code = status_code | ||
| self.headers = {} if headers is None else headers |
There was a problem hiding this comment.
Should we move this {} default up to the parameter declaration in these mock helpers?
class MockRawResponse(object):
def __init__(self, content, status_code, headers={}):
self.content = content
self.status_code = status_code
self.headers = headersNot sure if there are any places in the tests that explicitly pass headers=None though.
There was a problem hiding this comment.
Yea, that seems like a good simplification.
I can open up a follow-up PR.
| raise ServerException(response) | ||
| content_type = ( | ||
| response.headers.get("content-type") | ||
| if response.headers is not None |
There was a problem hiding this comment.
This null check is reasonable, but do we know when response.headers is possibly None?
I'm not familiar with the API, so I could see it possibly always defaulting to an empty dictionary. But maybe it is None in the case of client errors when there is no response at all?
There was a problem hiding this comment.
I think I added this check after I had seen it in my test cases. Not sure if it is because we have a specific instance where we're setting the headers to None.
This PR fixes an issue where we were trying to parse the response body as JSON for API responses that did not return JSON.
We now only parse the response body as JSON if it has a
Content-Typeofapplication/json.Closes #80.