Method: Match::Storage::GitLab::Client#handle_response_error

Defined in:
match/lib/match/storage/gitlab/client.rb

#handle_response_error(response, target_file = nil) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'match/lib/match/storage/gitlab/client.rb', line 97

def handle_response_error(response, target_file = nil)
  error_prefix      = "GitLab storage error:"
  file_debug_string = "File: #{target_file}" unless target_file.nil?
  api_debug_string  = "API: #{@api_v4_url}"
  debug_info        = "(#{[file_debug_string, api_debug_string].compact.join(', ')})"

  begin
    parsed = JSON.parse(response.body)
  rescue JSON::ParserError
  end

  if parsed && parsed["message"] && (parsed["message"]["name"] == ["has already been taken"])
    error_handler = :error
    error = "#{target_file} already exists in GitLab project #{@project_id}, file not uploaded"
  else
    error_handler = :user_error!
    error = "#{response.code}: #{response.body}"
  end
  error_message = [error_prefix, error, debug_info].join(' ')

  UI.send(error_handler, error_message)
end