builder/extra/cluster-home/lib/ruby/tungsten/api.rb
#
# Used internally by the calls to get and post to determine if the response was successful
#
Used internally by the calls to get and post to determine if the response was successful
Used internally by the calls to get and post to determine if the response was successful
def evaluate_response (api_server, response)
        if response.body
            hash_from_json = JSON.parse(response.body)
        end
        unless hash_from_json
          raise "Unable to parse API response from #{api_server}"
        end
        if TU.log_cmd_results?()
          TU.debug("Result: #{JSON.pretty_generate(hash_from_json)}")
        end
        if hash_from_json && hash_from_json["returnMessage"] && hash_from_json["returnCode"] && hash_from_json["returnCode"] != '200'
            return_object = {
                "httpStatus"    => hash_from_json["returnCode"],
                "message"       => hash_from_json["returnMessage"]
            } 
            if @@return_on_call_fail == :raise
                raise RuntimeError, "There was an error (#{hash_from_json["returnCode"]}) : #{hash_from_json["returnMessage"]}"
            end
            return return_object
        end
        if response.code != '200'
            if @@return_on_call_fail == :raise
                raise RuntimeError, "The request returned code #{response.code}"
            else
                return_object = {
                    "httpStatus"    => response.code,
                    "message"       => "unidentified error with code #{response.code}"
                } 
                return return_object
            end
        end
        return hash_from_json
    end
def evaluate_response ( api_server , response ) if response . body hash_from_json = JSON . parse ( response . body ) end unless hash_from_json raise "Unable to parse API response from #{api_server}" end if TU . log_cmd_results? ( ) TU . debug ( "Result: #{JSON.pretty_generate(hash_from_json)}" ) end if hash_from_json && hash_from_json [ "returnMessage" ] && hash_from_json [ "returnCode" ] && hash_from_json [ "returnCode" ] != '200' return_object = { "httpStatus" => hash_from_json [ "returnCode" ] , "message" => hash_from_json [ "returnMessage" ] } if @@return_on_call_fail == :raise raise RuntimeError , "There was an error (#{hash_from_json["returnCode"]}) : #{hash_from_json["returnMessage"]}" end return return_object end if response . code != '200' if @@return_on_call_fail == :raise raise RuntimeError , "The request returned code #{response.code}" else return_object = { "httpStatus" => response . code , "message" => "unidentified error with code #{response.code}" } return return_object end end return hash_from_json end
Used internally by the calls to get and post to determine if the response was successful
Used internally by the calls to get and post to determine if the response was successful
api_server
response