class Github::Error::ServiceError

def self.errors

Other tags:
    Api: - public

Returns:
  • (Hash[Integer, Object]) -
def self.errors
  @errors ||= Hash[
    descendants.map { |klass| [klass.new({}).http_status_code, klass] }
  ]
end

def self.http_status_code(code)

Other tags:
    Api: - public

Parameters:
  • code (Integer) --
def self.http_status_code(code)
  define_method(:http_status_code) { code }
end

def create_error_summary(data)

Other tags:
    Api: - private

Returns:
  • (String) -
def create_error_summary(data)
  if data[:error]
    return "\nError: #{data[:error]}"
  elsif data[:errors]
    message = "\nErrors:\n"
    message << data[:errors].map do |error|
      "Error: #{error.map { |k, v| "#{k}: #{v}" }.join(', ')}"
    end.join("\n")
  end
end

def create_message(response)

Other tags:
    Api: - private

Returns:
  • (String) -

Parameters:
  • response (Hash[Symbol]) --
def create_message(response)
  return if response.nil?
  message = "#{response[:method].to_s.upcase} "
  message << "#{response[:url]}: "
  message << "#{@status} - #{parse_body(@body)}"
  message
end

def decode_data(body)

Other tags:
    Api: - private

Parameters:
  • body (String) --
def decode_data(body)
  if body.respond_to?(:to_str) &&
     body.length >= MIN_BODY_LENGTH &&
     @headers[:content_type] =~ /json/
    JSON.parse(body, symbolize_names: true)
  else
    body
  end
end

def initialize(response)

Other tags:
    Api: - public

Parameters:
  • response (Hash[Symbol]) --
def initialize(response)
  @headers = response[:response_headers]
  @body    = response[:body]
  @status  = response[:status]
  super(create_message(response))
end

def parse_body(body)

Other tags:
    Api: - private
def parse_body(body)
  data = decode_data(body)
  return '' if data.nil? || data.empty?
  case data
  when Hash
    message = data[:message] ? data[:message] : ' '
    docs = data[:documentation_url]
    error = create_error_summary(data)
    message << error if error
    message << "\nSee: #{docs}" if docs
    message
  when String
    data
  end
end