Raise a response error, extracting as much information from the server's
 response as possible.

 @raise [HTTPError]

 @param [HTTP::Message] response
   the response object from the request
505480
def error(response)
      if response.body && response.body.match("missing client token")
        raise MissingTokenError
      end

      # Use the correct exception class
      case response
      when Net::HTTPClientError
        klass = HTTPClientError
      when Net::HTTPServerError
        klass = HTTPServerError
      else
        klass = HTTPError
      end

      if (response.content_type || '').include?("json")
        # Attempt to parse the error as JSON
        begin
          json = JSON.parse(response.body, JSON_PARSE_OPTIONS)

          if json[:errors]
            raise klass.new(address, response, json[:errors])
          end
        rescue JSON::ParserError; end
      end

      raise klass.new(address, response, [response.body])
    end
791589
def handle_exception(e)
    raise e unless defined?(e.response) && e.response != nil

    code = e.response[:status]
    error = Nokogiri::XML(e.response[:body])

    message = if error.xpath("m:error/m:message", @ds_namespaces).first
                error.xpath("m:error/m:message", @ds_namespaces).first.content
              else
                "Server returned error but no message."
              end
    raise ServiceError.new(code), message
  end
319743
def error_response(response):
    
    if response.status_code >= 500:
        raise exceptions.GeocodioServerError

    elif response.status_code == 403:
        raise exceptions.GeocodioAuthError

    elif response.status_code == 422:
        raise exceptions.GeocodioDataError(response.json()["error"])

    else:
        raise exceptions.GeocodioError(
            "Unknown service error (HTTP {0})".format(response.status_code)
        )
1328473
def raise_error(result)
      raise unless result.is_a? HTTP::Message

      err   = JSON.parse(result.body)
      klass = MantaClient.const_get err['code']
      raise klass, err['message']
    rescue NameError, TypeError, JSON::ParserError
      raise UnknownError, result.status.to_s + ': ' + result.body
    end
258412
def request_error!(exception)
      case exception
      when HTTP::Request::UnsupportedSchemeError, Addressable::URI::InvalidURIError
        raise Down::InvalidUrl, exception.message
      when HTTP::ConnectionError
        raise Down::ConnectionError, exception.message
      when HTTP::TimeoutError
        raise Down::TimeoutError, exception.message
      when HTTP::Redirector::TooManyRedirectsError
        raise Down::TooManyRedirects, exception.message
      when OpenSSL::SSL::SSLError
        raise Down::SSLError, exception.message
      else
        raise exception
      end
    end
525989
def _raise_error(self, status_code, raw_data):
        
        error_message = raw_data
        additional_info = None
        try:
            if raw_data:
                additional_info = json.loads(raw_data)
                error_message = additional_info.get('error', error_message)
                if isinstance(error_message, dict) and 'type' in error_message:
                    error_message = error_message['type']
        except (ValueError, TypeError) as err:
            logger.warning('Undecodable raw error response from server: %s', err)

        raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
62309
def handle_response(response)
      case response.code
      when 200..299
        response
      else
        if response.request.format == :json
          raise FreebaseAPI::ServiceError.new(response['error'])
        else
          raise FreebaseAPI::NetError.new('code' => response.code, 'message' => response.response.message)
        end
      end
    end
1124618
def validate(response)
      case response.code
      when 400 then fail Error::BadRequest, error_message(response)
      when 401 then fail Error::Unauthorized, error_message(response)
      when 403 then fail Error::Forbidden, error_message(response)
      when 404 then fail Error::NotFound, error_message(response)
      when 405 then fail Error::MethodNotAllowed, error_message(response)
      when 409 then fail Error::Conflict, error_message(response)
      when 500 then fail Error::InternalServerError, error_message(response)
      when 502 then fail Error::BadGateway, error_message(response)
      when 503 then fail Error::ServiceUnavailable, error_message(response)
      end

      handle_response(response)
    end
948820
def raise_for_response(self, responses):
        
        exception_messages = [self.client.format_exception_message(response) for response in responses]
        if len(exception_messages) == 1:
            message = exception_messages[0]
        else:
            message = "[%s]" % ", ".join(exception_messages)
        raise PostmarkerException(message)
724822
def handle_error(response):
    """"""
    status_code = response.status_code

    if status_code not in A_OK_HTTP_CODES:
        error_explanation = A_ERROR_HTTP_CODES.get(status_code)
        raise_error = "{}: {}".format(status_code, error_explanation)
        raise Exception(raise_error)
    else:
        return True
757661
def _fetch_all_error_message(self, response):
        

        response_content_string = response.content.decode()

        try:
            error_dict = converter.json_to_class(dict, response_content_string)

            return self._fetch_error_descriptions(error_dict)
        except ValueError:
            return [response_content_string]
952967
def _process_request(request)
      _error!(Errors::NotFoundError) unless request.valid?
      _validate_version(request)
      retval = _call_method(request)
      _response(request.post? ? 201 : 200, _prepare_response(retval))
    end
301023
function(message, response) {
    HttpError.call(this, message, code, description, response, false)
    Error.captureStackTrace(this, arguments.callee)
  }
633063
def raise_for_status(self):
        
        if not self.ok:
            reason = self.reason or 'No response from %s' % self.url
            if not self.status_code:
                raise HttpConnectionError(reason, response=self)

            if 400 <= self.status_code < 500:
                http_error_msg = '%s Client Error - %s - %s %s' % (
                    self.status_code, reason, self.request.method, self.url)
            else:
                http_error_msg = '%s Server Error - %s - %s %s' % (
                    self.status_code, reason, self.request.method, self.url)

            raise HttpRequestException(http_error_msg, response=self)
662557
def parse_response_for(response)
      case response
        when Net::HTTPOK, Net::HTTPCreated then return Response::Success.new(response)
        when Net::HTTPForbidden then raise Response::InvalidCredentials
        when Net::HTTPInternalServerError then raise Response::ServerError
        else raise Response::UnknownError
      end
    end
22478
def with_error_check(client, *response_msg_keys)
      raise "no block" if !block_given?

      begin
        response = yield
        hash_response = response.to_hash
        statuses = hash_response.fetch_in(*response_msg_keys)
        
        if statuses.is_a?(Array)
          all_statuses = statuses
        else
          all_statuses = [statuses]
        end
        
        errors = all_statuses.map{|s| single_error_check(client, s)}.compact
      rescue Exception=>e
        Rews.log{|logger| logger.warn(e)}
        tag_exception(e, :savon_response=>response)
        raise e
      end

      raise Error.new(errors.join("\n")) if !errors.empty?
      statuses
    end
721202
def _handle_response(self, response):
        
        if not response.ok:
            raise ScrapydResponseError(
                "Scrapyd returned a {0} error: {1}".format(
                    response.status_code,
                    response.text))

        try:
            json = response.json()
        except ValueError:
            raise ScrapydResponseError("Scrapyd returned an invalid JSON "
                                       "response: {0}".format(response.text))
        if json['status'] == 'ok':
            json.pop('status')
            return json
        elif json['status'] == 'error':
            raise ScrapydResponseError(json['message'])