<commit_before>module Eventbrite
  class Error < StandardError
    attr_reader :type, :message

    def self.from_response(response)
      error_type, error_message = parse_error(response.body)
      new(error_type, error_message)
    end

    def self.parse_error(body)
      error = body[:error]

      if error.nil?
        ['', nil]
      elsif String === error
        ['', error]
      else
        [error[:error_type], error[:error_message]]
      end
    end

    def initialize(type, message)
      @type = type
      @message = message
    end

    def inspect
      vars = self.instance_variables.
        map{|v| "#{v}=#{instance_variable_get(v).inspect}"}.join(", ")
      "<#{self.class}: #{vars}>"
    end
  end
end<commit_msg>Refactor Error to mirror Twitter::Error<commit_after>module Eventbrite
  class Error < StandardError
    attr_reader :message, :description, :code

    class << self
      def from_response(response)
        message, description, code = parse_error(response.body)
        new(message, description, code)
      end

      def errors
        @errors ||= {
          401 => Eventbrite::Error::Unauthorized
        }

      end

    private
      def parse_error(body)
        if body.nil?
          ['', '', nil]
        else
          [
            body[:error],
            body[:error_description],
            body[:error]
          ]
        end
      end

    end

    def initialize(message = '', description = '', code = nil)
      super(description)

      @message = message
      @description = description
      @code = code
    end

    # Raised when Eventbrite returns a 4xx HTTP status code
    class ClientError < self; end

    # Raised when Twitter returns the HTTP status code 401
    class Unauthorized < ClientError; end

  end
end
{'fraction_non_alphanumeric': 0.10050251256281408, 'fraction_numerical': 0.003908431044109436, 'mean_word_length': 2.1549295774647885, 'pattern_counts': {'":': 0, '<': 10, '<?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': '1271639', 'n_tokens_mistral': 521, 'n_tokens_neox': 500, 'n_words': 135}