lib/gitlab/request.rb in gitlab-3.4.0 vs lib/gitlab/request.rb in gitlab-3.5.0
- old
+ new
@@ -17,10 +17,14 @@
if body.is_a? Hash
ObjectifiedHash.new body
elsif body.is_a? Array
body.collect! { |e| ObjectifiedHash.new(e) }
+ elsif body
+ true
+ elsif !body
+ false
elsif body.nil?
false
else
raise Error::Parsing.new "Couldn't parse a response body"
end
@@ -67,10 +71,11 @@
when 401; raise Error::Unauthorized.new error_message(response)
when 403; raise Error::Forbidden.new error_message(response)
when 404; raise Error::NotFound.new error_message(response)
when 405; raise Error::MethodNotAllowed.new error_message(response)
when 409; raise Error::Conflict.new error_message(response)
+ when 422; raise Error::Unprocessable.new error_message(response)
when 500; raise Error::InternalServerError.new error_message(response)
when 502; raise Error::BadGateway.new error_message(response)
when 503; raise Error::ServiceUnavailable.new error_message(response)
end
@@ -107,20 +112,26 @@
options.merge!(self.httparty)
end
end
def error_message(response)
+ parsed_response = response.parsed_response
+ message = parsed_response.message || parsed_response.error
+
"Server responded with code #{response.code}, message: " \
- "#{handle_error(response.parsed_response.message)}. " \
+ "#{handle_error(message)}. " \
"Request URI: #{response.request.base_uri}#{response.request.path}"
end
# Handle error response message in case of nested hashes
def handle_error(message)
- if message.is_a? Gitlab::ObjectifiedHash
+ 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).join(' ')}"
end.join(', ')
+ when Array
+ message.join(' ')
else
message
end
end