Validates response body

 @param [Object] response

 @raise [Exceptions::Validation]  When there is a missing required header..
10221
def validate_body!(response)
      return unless media_type
      return if media_type.kind_of? SimpleMediaType

      errors = self.media_type.validate(self.media_type.load(response.body))
      if errors.any?
        message = "Invalid response body for #{media_type.identifier}." +
          "Errors: #{errors.inspect}"
          raise Exceptions::Validation.new(message, errors: errors)
      end

    end
454713
def parse_response(response)
      case response.content_type
      when JSON_CONTENT_TYPE
        JSON.parse(response.body, quirks_mode: true, symbolize_names: true)
      else
        response.body
      end
    end
665887
def handle_response(response)
      # Check our response code
      check_response_fail(response)
      return nil if blank?(response.body)

      # Return a bunch of mashes as the body if we're JSON
      begin
        response.body = JSON.parse(response.body, max_nesting: false)
        response.body = if response.body.is_a? Array
                        response.body.map { |r| Hashie::Mash.new(r) }
                      else
                        Hashie::Mash.new(response.body)
                      end
      rescue => exception
        raise "JSON parsing failed. Error details: #{exception}"
      ensure
        return response
      end
    end
1305790
def check_roads_body_error(response, body)
        error = body[:error]
        return unless error

        case error[:status]
          when 'INVALID_ARGUMENT'
            if error[:message] == 'The provided API key is invalid.'
              raise GoogleMapsService::Error::RequestDeniedError.new(response), error[:message]
            end
            raise GoogleMapsService::Error::InvalidRequestError.new(response), error[:message]
          when 'PERMISSION_DENIED'
            raise GoogleMapsService::Error::RequestDeniedError.new(response), error[:message]
          when 'RESOURCE_EXHAUSTED'
            raise GoogleMapsService::Error::RateLimitError.new(response), error[:message]
          else
            raise GoogleMapsService::Error::ApiError.new(response), error[:message]
        end
      end
701136
def _validation(response):
    
    h = hashlib.sha256(response.key_authorization.encode("utf-8"))
    return b64encode(h.digest()).decode()
570252
def process_response(response)
      response = create_hash response
      if response['status'].nil?
        raise Hoiio::ServerError
      elsif STATUS_SUCCESS != response['status']
        raise Hoiio::ResponseError.new response['status'], response['status']
      end
      response
    end
390767
function (response, body) {
          var tokenResponse;
          try {
             tokenResponse = self._handlePollingResponse(body);
          } catch (e) {
             self._log.error('Error validating get token response', e, true);
             callback(null, e);
             return;
          }
        
          callback(null, tokenResponse);
       }
211795
def errors
      if response.decoded_body
        response.decoded_body['errors'] ||
          response.decoded_body[:errors] ||
          response.decoded_body
      else
        response.body
      end
    end
356795
function validateBody(err, body) {
      body = tryParse(body);

      if (err || !body) {
        return next(err || new Error('Unparsable response with statusCode ' + statusCode));
      }

      if (statusCode !== 200) {
        return next(new Error(body.message || 'Invalid status code ' + statusCode));
      }

      next(null, body);
    }
1106753
def transform_error2_response(error)
        response = ["#{error.message}: #{error.http_body}", error.http_code]
        def response.body
          self[0]
        end
        def response.code
          self[1]
        end
        response
      end
496841
def body
      raise RequestError, 'The request requires a HTTP method.' unless @http_method
      raise RequestError, 'The payload needs to be a hash.' unless @payload.to_s.empty? || @payload.is_a?(Hash)

      res = Net::HTTP.start(uri.hostname, Yoti.configuration.api_port, use_ssl: https_uri?) do |http|
        signed_request = SignedRequest.new(unsigned_request, path, @payload).sign
        http.request(signed_request)
      end

      raise RequestError, "Unsuccessful Yoti API call: #{res.message}" unless res.code == '200'

      res.body
    end
988793
def validate
      return if !!@validation_deferred
      if self.scheme != nil && self.ip_based? &&
          (self.host == nil || self.host.empty?) &&
          (self.path == nil || self.path.empty?)
        raise InvalidURIError,
          "Absolute URI missing hierarchical segment: '#{self.to_s}'"
      end
      if self.host == nil
        if self.port != nil ||
            self.user != nil ||
            self.password != nil
          raise InvalidURIError, "Hostname not supplied: '#{self.to_s}'"
        end
      end
      if self.path != nil && !self.path.empty? && self.path[0..0] != SLASH &&
          self.authority != nil
        raise InvalidURIError,
          "Cannot have a relative path with an authority set: '#{self.to_s}'"
      end
      if self.path != nil && !self.path.empty? &&
          self.path[0..1] == SLASH + SLASH && self.authority == nil
        raise InvalidURIError,
          "Cannot have a path with two leading slashes " +
          "without an authority set: '#{self.to_s}'"
      end
      unreserved = CharacterClasses::UNRESERVED
      sub_delims = CharacterClasses::SUB_DELIMS
      if !self.host.nil? && (self.host =~ /[<>{}\/\\\?\#\@"[[:space:]]]/ ||
          (self.host[/^\[(.*)\]$/, 1] != nil && self.host[/^\[(.*)\]$/, 1] !~
          Regexp.new("^[#{unreserved}#{sub_delims}:]*$")))
        raise InvalidURIError, "Invalid character in host: '#{self.host.to_s}'"
      end
      return nil
    end
1230743
def validate(response)
      case response.code
        when 400; raise Error::BadRequest.new error_message(response)
        when 401; raise Error::Unauthorized.new error_message(response)
        when 403; raise Error::Forbidden.new error_message(response)
        when 404; raise Error::NotFound.new error_message(response)
        when 405; raise Error::MethodNotAllowed.new error_message(response)
        when 409; raise Error::Conflict.new error_message(response)
        when 500; raise Error::InternalServerError.new error_message(response)
        when 502; raise Error::BadGateway.new error_message(response)
        when 503; raise Error::ServiceUnavailable.new error_message(response)
      end

      response.parsed_response
    end
412901
def validate_content_type!(response)
      return unless media_type

      response_content_type = response.content_type
      expected_content_type = Praxis::MediaTypeIdentifier.load(media_type.identifier)

      unless expected_content_type.match(response_content_type)
        raise Exceptions::Validation.new(
          "Bad Content-Type header. #{response_content_type}" +
          " is incompatible with #{expected_content_type} as described in response: #{self.name}"
        )
      end
    end
1345090
def raise_exception(response)
      raise Wanikani::InvalidKey, "The API key used for this request is invalid." and return if response.status == 401

      message = if response.body.is_a?(Hash) and response.body.has_key?("error")
                  response.body["error"]["message"]
                else
                  "Status code: #{response.status}"
                end
      raise Wanikani::Exception, "There was an error fetching the data from WaniKani (#{message})"
    end
1347139
def check_body_error(response, body)
      case body[:status]
      when 'OK', 'ZERO_RESULTS'
        # Do-nothing
      when 'OVER_QUERY_LIMIT'
        raise GoogleMapsService::Error::RateLimitError.new(response), body[:error_message]
      when 'REQUEST_DENIED'
        raise GoogleMapsService::Error::RequestDeniedError.new(response), body[:error_message]
      when 'INVALID_REQUEST'
        raise GoogleMapsService::Error::InvalidRequestError.new(response), body[:error_message]
      else
        raise GoogleMapsService::Error::ApiError.new(response), body[:error_message]
      end
    end
1302250
def _validate_response(response):
    '''
    

    '''
    if not response:
        return False, 'Unable to validate response from device.'
    elif 'msg' in response:
        if 'line' in response['msg']:
            if response['msg']['line'] == 'already at the top':
                return True, response
            elif response['msg']['line'] == 'already at the bottom':
                return True, response
            else:
                return False, response
        elif response['msg'] == 'command succeeded':
            return True, response
        else:
            return False, response
    elif 'status' in response:
        if response['status'] == "success":
            return True, response
        else:
            return False, response
    else:
        return False, response