Example #1
0
 def parse_response(self, resp):
     payload = json.loads(resp.content)
     if resp.status_code == 200:
         return payload
     elif resp.status_code == 401:
         raise error.AuthenticationError(payload['errors'][0]['message'],
             resp.content, resp.status_code, resp)
     elif resp.status_code in [404, 422]:
         raise error.InvalidRequestError(payload['errors'][0]['message'],
             resp.content, resp.status_code, resp)
     else:
         raise error.APIError(payload['errors'][0]['message'],
                 resp.content, resp.status_code, resp) #pragma: no cover
Example #2
0
    def parse_response(self, resp):
        if resp.status_code == 504:
            raise error.APIConnectionError(resp.content or resp.reason,  # pragma: no cover
                                           resp.content, resp.status_code, resp)

        payload = resp.json()
        if resp.status_code == 200:
            return payload
        elif resp.status_code == 401:
            raise error.AuthenticationError(payload['error']['message'],
                                            resp.content, resp.status_code, resp)
        elif resp.status_code in [404, 422]:
            raise error.InvalidRequestError(payload['error']['message'],
                                            resp.content, resp.status_code, resp)
        else:  # pragma: no cover
            raise error.APIError(payload['error']['message'], resp.content, resp.status_code, resp)