class Gitlab::Error::ResponseError

Custom error class for rescuing from HTTP response errors.

def build_error_message

Returns:
  • (String) -
def build_error_message
  parsed_response = @response.parsed_response
  message = check_error_keys(parsed_response)
  "Server responded with code #{@response.code}, message: " \
  "#{handle_message(message)}. " \
  "Request URI: #{@response.request.base_uri}#{@response.request.path}"
end

def check_error_keys(resp)

object responds to and return that, otherwise return the original.
Error keys vary across the API, find the first key that the parsed_response
def check_error_keys(resp)
  key = POSSIBLE_MESSAGE_KEYS.find { |k| resp.respond_to?(k) }
  key ? resp.send(key) : resp
end

def handle_message(message)

Handle error response message in case of nested hashes
def handle_message(message)
  case message
  when Gitlab::ObjectifiedHash
    message.to_h.sort.map do |key, val|
      "'#{key}' #{(val.is_a?(Hash) ? val.sort.map { |k, v| "(#{k}: #{v.join(' ')})" } : [val].flatten).join(' ')}"
    end.join(', ')
  when Array
    message.join(' ')
  else
    message
  end
end

def initialize(response)

def initialize(response)
  @response = response
  super(build_error_message)
end

def response_message

Returns:
  • (String) -
def response_message
  @response.parsed_response.message
end

def response_status

Returns:
  • (Integer) -
def response_status
  @response.code
end