Commit 15448f95 authored by Mark Chao's avatar Mark Chao

Merge branch '330603-show-certain-customersdot-exceptions-to-the-end-user' into 'master'

Show user facing errors for CustomersDot API calls

See merge request gitlab-org/gitlab!62367
parents a44d81f1 48440e25
......@@ -36,18 +36,7 @@ module Gitlab
private
def error_message
_('We encountered an error and our team has been notified. Please try again.')
end
def reparse_response(response)
result = parse_response(response)
if !result[:success] && result[:data]
track_exception(result[:data][:errors])
result[:data][:errors] = error_message
end
result
_('Our team has been notified. Please try again.')
end
def track_exception(message)
......@@ -61,7 +50,7 @@ module Gitlab
def http_get(path, headers)
response = Gitlab::HTTP.get("#{base_url}/#{path}", headers: headers)
reparse_response(response)
parse_response(response)
rescue *Gitlab::HTTP::HTTP_ERRORS => e
track_exception(e.message)
{ success: false, data: { errors: error_message } }
......@@ -70,7 +59,7 @@ module Gitlab
def http_post(path, headers, params = {})
response = Gitlab::HTTP.post("#{base_url}/#{path}", body: params.to_json, headers: headers)
reparse_response(response)
parse_response(response)
rescue *Gitlab::HTTP::HTTP_ERRORS => e
track_exception(e.message)
{ success: false, data: { errors: error_message } }
......@@ -79,7 +68,7 @@ module Gitlab
def http_put(path, headers, params = {})
response = Gitlab::HTTP.put("#{base_url}/#{path}", body: params.to_json, headers: headers)
reparse_response(response)
parse_response(response)
rescue *Gitlab::HTTP::HTTP_ERRORS => e
track_exception(e.message)
{ success: false, data: { errors: error_message } }
......
......@@ -6,7 +6,7 @@ RSpec.describe Gitlab::SubscriptionPortal::Clients::REST do
let(:client) { Gitlab::SubscriptionPortal::Client }
let(:http_response) { nil }
let(:http_method) { :post }
let(:error_message) { 'We encountered an error and our team has been notified. Please try again.' }
let(:error_message) { 'Our team has been notified. Please try again.' }
let(:gitlab_http_response) do
double(code: http_response.code, response: http_response, body: {}, parsed_response: {})
end
......@@ -24,9 +24,7 @@ RSpec.describe Gitlab::SubscriptionPortal::Clients::REST do
shared_examples 'when http call raises an exception' do
it 'overrides the error message' do
exception = Gitlab::HTTP::HTTP_ERRORS.first.new
tracked_exception = Gitlab::SubscriptionPortal::Clients::REST::SubscriptionPortalRESTException.new(exception.message)
allow(Gitlab::HTTP).to receive(http_method).and_raise(exception)
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(tracked_exception)
result = subject
......@@ -40,10 +38,8 @@ RSpec.describe Gitlab::SubscriptionPortal::Clients::REST do
it 'has a unprocessable entity status' do
allow(Gitlab::HTTP).to receive(http_method).and_return(gitlab_http_response)
expect(Gitlab::ErrorTracking).to receive(:track_exception)
expect(subject[:success]).to eq(false)
expect(subject[:data][:errors]).to eq(error_message)
end
end
......@@ -52,10 +48,8 @@ RSpec.describe Gitlab::SubscriptionPortal::Clients::REST do
it 'has a server error status' do
allow(Gitlab::HTTP).to receive(http_method).and_return(gitlab_http_response)
expect(Gitlab::ErrorTracking).to receive(:track_exception)
expect(subject[:success]).to eq(false)
expect(subject[:data][:errors]).to eq(error_message)
end
end
......
......@@ -23334,6 +23334,9 @@ msgstr ""
msgid "Otherwise, click the link below to complete the process:"
msgstr ""
msgid "Our team has been notified. Please try again."
msgstr ""
msgid "Out-of-compliance with this project's policies and should be removed"
msgstr ""
......@@ -36377,9 +36380,6 @@ msgstr ""
msgid "We don't have enough data to show this stage."
msgstr ""
msgid "We encountered an error and our team has been notified. Please try again."
msgstr ""
msgid "We have found the following errors:"
msgstr ""
......
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