Skip to content

Commit a4f52e5

Browse files
committed
1680: Improve error when exporting through an account_link
1 parent fed3b13 commit a4f52e5

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

app/services/exercise_service/push_external.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ def execute
1818
request.body = body
1919
end
2020

21-
response.success? ? nil : response.body
21+
if response.success?
22+
nil
23+
else
24+
response.status == 401 ? I18n.t('exercises.export_codeharbor.not_authorized') : response.body
25+
end
2226
rescue StandardError => e
2327
e.message
2428
end

config/locales/de/exercise.yml

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ de:
102102
error: Es ist ein Fehler bei der Kommunikation mit CodeHarbor aufgetreten.
103103
export_failed: 'Export ist fehlgeschlagen.<br>ID: %{id}<br>Title: %{title}<br><br>Error: %{error}'
104104
label: Zu CodeHarbor exportieren
105+
not_authorized: Die Autorisierung mit CodeHarbor konnte nicht hergestellt werden. Ist der API-Schlüssel korrekt?
105106
successfully_exported: 'Aufgabe wurde erfolgreich exportiert.<br>ID: %{id}<br>Title: %{title}'
106107
external_users:
107108
statistics:

config/locales/en/exercise.yml

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ en:
102102
error: An error occurred while contacting CodeHarbor
103103
export_failed: 'Export has failed.<br>ID: %{id}<br>Title: %{title}<br><br>Error: %{error}'
104104
label: Export to CodeHarbor
105+
not_authorized: Authorization with could not be established with CodeHarbor. Is the API Key correct?
105106
successfully_exported: 'Exercise has been successfully exported.<br>ID: %{id}<br>Title: %{title}'
106107
external_users:
107108
statistics:

spec/services/exercise_service/push_external_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@
5353

5454
it { is_expected.to be response }
5555
end
56+
57+
context 'when response status is 401' do
58+
let(:status) { 401 }
59+
let(:response) { I18n.t('exercises.export_codeharbor.not_authorized') }
60+
61+
it { is_expected.to eql response }
62+
end
5663
end
5764

5865
context 'when an error occurs' do

0 commit comments

Comments
 (0)