Raises an exception for unsuccessful responses
354346
def mapping!(*args)
      mapping(*args)
      raise RuntimeError, response.body unless response.success?
    end
1072820
def _raise_for_status(self, response, explanation=None):
        """"""
        try:
            response.raise_for_status()
        except requests.exceptions.HTTPError as e:
            if e.response.status_code == 404:
                raise errors.NotFound(e, response, explanation=explanation)
            raise errors.APIError(e, response, explanation=explanation)
1317394
def _raise_for_status(response):
    '''
    
    '''
    http_error_msg = ""

    if 400 <= response.status_code < 500:
        http_error_msg = "{0} Client Error: {1}".format(response.status_code,
                                                        response.reason)

    elif 500 <= response.status_code < 600:
        http_error_msg = "{0} Server Error: {1}".format(response.status_code,
                                                        response.reason)

    if http_error_msg:
        try:
            more_info = response.json().get("message")
        except ValueError:
            more_info = None
        if more_info and more_info.lower() != response.reason.lower():
            http_error_msg += ".\n\t{0}".format(more_info)
        raise requests.exceptions.HTTPError(http_error_msg, response=response)
812649
def _adapt_response(self, response):
        """"""
        if 'application/json' in response.headers['content-type']:
            body = response.json()
            status = response.status_code

            if body.get('error'):
                return self._simple_response_to_error_adapter(status, body)

        raise UnknownHttpError(response)
403030
def _raise_for_status(response):
    

    http_error_msg = ''

    if 400 <= response.status_code < 500:
        http_error_msg = '%s Client Error: %s for url: %s' % (
            response.status_code, response.reason, response.url)

    elif 500 <= response.status_code < 600:
        http_error_msg = '%s Server Error: %s for url: %s' % (
            response.status_code, response.reason, response.url)

    if http_error_msg:
        spacetrack_error_msg = None

        try:
            json = response.json()
            if isinstance(json, Mapping):
                spacetrack_error_msg = json['error']
        except (ValueError, KeyError):
            pass

        if not spacetrack_error_msg:
            spacetrack_error_msg = response.text

        if spacetrack_error_msg:
            http_error_msg += '\nSpace-Track response:\n' + spacetrack_error_msg

        raise requests.HTTPError(http_error_msg, response=response)
891792
def raise_error
      klass = case @response.to_s
        when "RestClient::BadRequest" then TodaysPlan::BadRequestError
        when "RestClient::Unauthorized" then  TodaysPlan::UnauthorizedError
        when "RestClient::NotFound" then TodaysPlan::NotFoundError
        else
          TodaysPlan::ServerError
        end
      raise klass.new(body['code'], body['message'], body['resolve'])
    end
1146983
def _raise_or_extract(self, response):
        

        try:
            data = response.json()
        except ValueError:
            raise JoeException("The server responded with an unexpected format ({}). Is the API url correct?". format(response.status_code))

        try:
            if response.ok:
                return data['data']
            else:
                error = data['errors'][0]
                raise ApiError(error)
        except (KeyError, TypeError):
            raise JoeException("Unexpected data ({}). Is the API url correct?". format(response.status_code))
248130
def _raise_or_append_exception(self):
        
        message = (
            'Connection dead, no heartbeat or data received in >= '
            '%ds' % (
                self._interval * 2
            )
        )
        why = AMQPConnectionError(message)
        if self._exceptions is None:
            raise why
        self._exceptions.append(why)
992282
def _handle_client_exception():
    
    try:
        yield

    except _ClientException as exception:
        if exception.http_status in _ERROR_CODES:
            raise _ERROR_CODES[exception.http_status](
                exception.http_reason)
        raise
1154128
def _raise_error_from_response(data):
    """"""
    # Check the meta-data for why this request failed
    meta = data.get('meta')
    if meta:
        # Account for foursquare conflicts
        # see: https://developer.foursquare.com/overview/responses
        if meta.get('code') in (200, 409): return data
        exc = error_types.get(meta.get('errorType'))
        if exc:
            raise exc(meta.get('errorDetail'))
        else:
            _log_and_raise_exception('Unknown error. meta', meta)
    else:
        _log_and_raise_exception('Response format invalid, missing meta property. data', data)
138261
def raise_status(response):
    
    if response.status != 200:
        if response.status == 401:
            raise StrawPollException('Unauthorized', response)
        elif response.status == 403:
            raise StrawPollException('Forbidden', response)
        elif response.status == 404:
            raise StrawPollException('Not Found', response)
        else:
            response.raise_for_status()
868375
def _resp_exception(self, resp):
        

        message = [
            'Url: [ %s ] Reason: [ %s ] Request: [ %s ] Status Code: [ %s ]. ',
            resp.url,
            resp.reason,
            resp.request,
            resp.status_code
        ]

        # Check to make sure we have all the bits needed
        if not hasattr(resp, 'status_code'):
            message[0] += 'No Status to check. Turbolift will retry...'
            raise exceptions.SystemProblem(message)
        elif resp is None:
            message[0] += 'No response information. Turbolift will retry...'
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 401:
            message[0] += (
                'Turbolift experienced an Authentication issue. Turbolift'
                ' will retry...'
            )
            self.job_args.update(auth.authenticate(self.job_args))
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 404:
            message[0] += 'Item not found.'
            LOG.debug(*message)
        elif resp.status_code == 409:
            message[0] += (
                'Request Conflict. Turbolift is abandoning this...'
            )
        elif resp.status_code == 413:
            return_headers = resp.headers
            retry_after = return_headers.get('retry_after', 10)
            cloud_utils.stupid_hack(wait=retry_after)
            message[0] += (
                'The System encountered an API limitation and will'
                ' continue in [ %s ] Seconds' % retry_after
            )
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 502:
            message[0] += (
                'Failure making Connection. Turbolift will retry...'
            )
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 503:
            cloud_utils.stupid_hack(wait=10)
            message[0] += 'SWIFT-API FAILURE'
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 504:
            cloud_utils.stupid_hack(wait=10)
            message[0] += 'Gateway Failure.'
            raise exceptions.SystemProblem(message)
        elif resp.status_code >= 300:
            message[0] += 'General exception.'
            raise exceptions.SystemProblem(message)
        else:
            LOG.debug(*message)
1228856
def _request_with_error_ignored(self, rd):
        """"""
        try:
            return self._request(rd)
        except Exception as err:
            # log as warning and ignore namelist operation failures
            LOG.warning(six.text_type(err))
727139
def raise_db_exception(self):
        
        if not self.messages:
            raise tds_base.Error("Request failed, server didn't send error message")
        msg = None
        while True:
            msg = self.messages[-1]
            if msg['msgno'] == 3621:  # the statement has been terminated
                self.messages = self.messages[:-1]
            else:
                break

        error_msg = ' '.join(m['message'] for m in self.messages)
        ex = _create_exception_by_message(msg, error_msg)
        raise ex
378385
def _catch_index_error(self, response):
        
        code, headers, raw_data = response
        if not raw_data:
            return
        data = json.loads(raw_data)
        if not data or not data.get('errors'):
            return
        try:
            error_dict = data['items'][0]['index']
            message = error_dict['error']
        except (KeyError, IndexError):
            return
        raise exception_response(400, detail=message)
860521
def _handle_http_errors(response):
    
    code = response.status_code
    if 200 <= code < 400:
        return response
    elif code in (403, 404):
        raise {403: _ObjectPermissionError,
               404: _ObjectNotFoundError}[code](response.reason)
    response.raise_for_status()
596525
def _adapt_response(self, response):
        """"""
        errors, meta = super(ServerError, self)._adapt_response(response)
        return errors[0], meta