<commit_before>module Gooru
  class Response
    attr_reader :data

    def initialize(weary_response)
      @data = parse(weary_response.body)
    end

    def success?
      data.has_key?("error") == false
    end

  private

    def parse(body)
      if body.match(/^error:(.*)/)
        { "error" => Regexp.last_match[1] }
      else
        MultiJson.decode(body)
      end
    end

  end
end<commit_msg>Handle more Gooru error possibilities.<commit_after>module Gooru
  class Response
    attr_reader :data
    attr_reader :status

    def initialize(weary_response)
      @data = parse(weary_response.body)
      @status = weary_response.status
    end

    def error?
      has_error_key? ||
      internal_server_error?
    end

    def error_message
      if has_error_key?
        data["error"]
      elsif internal_server_error?
        data["status"]
      else
        ""
      end
    end

    def success?
      !error?
    end

  private

    def has_error_key?
      data.has_key?("error")
    end

    def internal_server_error?
      status == 500
    end

    def parse(body)
      if body.match(/^error:(.*)/)
        { "error" => Regexp.last_match[1] }
      else
        MultiJson.decode(body)
      end
    end

  end
end
{'fraction_non_alphanumeric': 0.09309791332263243, 'fraction_numerical': 0.0040128410914927765, 'mean_word_length': 2.0563725490196076, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1318504', 'n_tokens_mistral': 420, 'n_tokens_neox': 399, 'n_words': 89}