Commit b6a256a4 authored by Rubén Dávila's avatar Rubén Dávila

Improve consistency when handling error messages

parent 28fe92a1
...@@ -8,7 +8,7 @@ module GitlabSubscriptions ...@@ -8,7 +8,7 @@ module GitlabSubscriptions
if response[:success] if response[:success]
{ success: true } { success: true }
else else
{ success: false, errors: response.dig(:data, 'errors') } { success: false, errors: response.dig(:data, :errors) }
end end
end end
......
...@@ -27,13 +27,15 @@ module Gitlab ...@@ -27,13 +27,15 @@ module Gitlab
end end
def parse_response(http_response) def parse_response(http_response)
parsed_response = http_response.parsed_response
case http_response.response case http_response.response
when Net::HTTPSuccess when Net::HTTPSuccess
{ success: true, data: http_response.parsed_response } { success: true, data: parsed_response }
when Net::HTTPUnprocessableEntity when Net::HTTPUnprocessableEntity
{ success: false, data: http_response.parsed_response } { success: false, data: { errors: parsed_response['errors'] } }
else else
{ success: false, data: "HTTP status code: #{http_response.code}" } { success: false, data: { errors: "HTTP status code: #{http_response.code}" } }
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment