Пример #1
0
    def process_ubersmith_response(response):
        if response.status_code < 200 or response.status_code >= 400:
            raise get_exception_for(status_code=response.status_code)

        if response.headers['content-type'] == 'application/json':
            response_json = response.json()
            if not response_json['status']:
                raise UbersmithException(response_json['error_code'],
                                         response_json['error_message'])

            return response_json['data']

        return response.content
Пример #2
0
    def process_request(self, http_method, **kwargs):
        callable_http_method = getattr(requests, http_method)
        response = callable_http_method(self.url, auth=(self.user, self.password), **kwargs)

        if response.status_code < 200 or response.status_code >= 400:
            raise get_exception_for(status_code=response.status_code)

        response_json = response.json()
        if not response_json['status']:
            raise UbersmithException(
                500,
                "error {0}, {1}".format(response_json['error_code'], response_json['error_message'])
            )

        return response.json()["data"]
    def process_ubersmith_response(response):
        if response.status_code < 200 or response.status_code >= 400:
            raise get_exception_for(status_code=response.status_code)

        if response.headers['content-type'] == 'application/json':
            response_json = response.json()
            if not response_json['status']:
                raise UbersmithException(
                    response_json['error_code'],
                    response_json['error_message']
                )

            return response_json['data']

        return response.content