<commit_before>module MWS
  module API

    class Response < Hashie::Rash

      def self.parse(body, name, params)
        return body unless body.is_a?(Hash)

        rash = self.new(body)
        if !rash.keys.nil? && rash.keys.first == "amazon_envelope"
          rash
        else
          raise BadResponseError, "received non-matching response type #{rash.keys} code: #{rash.try(:error_response).try(:error).try(:code)} message: #{rash.try(:error_response).try(:error).try(:message)}" if rash["#{name}_response"].nil? 
          rash = rash["#{name}_response"]

          if rash = rash["#{name}_result"]
            # only runs mods if correct result is present
            params[:mods].each {|mod| mod.call(rash) } if params[:mods]
            rash
          end
        end
      end

      def self.handle_error_response(error)
        msg = "#{error.code}: #{error.message}"
        msg << " -- #{error.detail}" unless error.detail.nil?
        raise ErrorResponse, msg
      end<commit_msg>local var<commit_after>module MWS
  module API

    class Response < Hashie::Rash

      def self.parse(body, name, params)
        return body unless body.is_a?(Hash)

        rash = self.new(body)
        if !rash.keys.nil? && rash.keys.first == "amazon_envelope"
          rash
        else
          err_msg = rash.try(:error_response).try(:error)
          raise BadResponseError, "received non-matching response type #{rash.keys} code: #{err_msg.try(:code)} message: #{err_msg.try(:message)}" if rash["#{name}_response"].nil?
          rash = rash["#{name}_response"]

          if rash = rash["#{name}_result"]
            # only runs mods if correct result is present
            params[:mods].each {|mod| mod.call(rash) } if params[:mods]
            rash
          end
        end
      end

      def self.handle_error_response(error)
        msg = "#{error.code}: #{error.message}"
        msg << " -- #{error.detail}" unless error.detail.nil?
        raise ErrorResponse, msg
      end
{'fraction_non_alphanumeric': 0.1362955566650025, 'fraction_numerical': 0.0, 'mean_word_length': 2.34, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6859880', 'n_tokens_mistral': 618, 'n_tokens_neox': 599, 'n_words': 144}