diff --git a/app/services/exercise_service/push_external.rb b/app/services/exercise_service/push_external.rb index 69c5234a2..5c099486e 100644 --- a/app/services/exercise_service/push_external.rb +++ b/app/services/exercise_service/push_external.rb @@ -18,7 +18,11 @@ def execute request.body = body end - response.success? ? nil : response.body + if response.success? + nil + else + response.status == 401 ? I18n.t('exercises.export_codeharbor.not_authorized') : response.body + end rescue StandardError => e e.message end diff --git a/config/locales/de/exercise.yml b/config/locales/de/exercise.yml index 97b144bfb..d7dd93b49 100644 --- a/config/locales/de/exercise.yml +++ b/config/locales/de/exercise.yml @@ -102,6 +102,7 @@ de: error: Es ist ein Fehler bei der Kommunikation mit CodeHarbor aufgetreten. export_failed: 'Export ist fehlgeschlagen.
ID: %{id}
Title: %{title}

Error: %{error}' label: Zu CodeHarbor exportieren + not_authorized: Die Autorisierung mit CodeHarbor konnte nicht hergestellt werden. Ist der API-Schlüssel korrekt? successfully_exported: 'Aufgabe wurde erfolgreich exportiert.
ID: %{id}
Title: %{title}' external_users: statistics: diff --git a/config/locales/en/exercise.yml b/config/locales/en/exercise.yml index 3f9e04b15..29f8ccce4 100644 --- a/config/locales/en/exercise.yml +++ b/config/locales/en/exercise.yml @@ -102,6 +102,7 @@ en: error: An error occurred while contacting CodeHarbor export_failed: 'Export has failed.
ID: %{id}
Title: %{title}

Error: %{error}' label: Export to CodeHarbor + not_authorized: Authorization with could not be established with CodeHarbor. Is the API Key correct? successfully_exported: 'Exercise has been successfully exported.
ID: %{id}
Title: %{title}' external_users: statistics: diff --git a/spec/services/exercise_service/push_external_spec.rb b/spec/services/exercise_service/push_external_spec.rb index 347d3d86e..cf9c1477d 100644 --- a/spec/services/exercise_service/push_external_spec.rb +++ b/spec/services/exercise_service/push_external_spec.rb @@ -53,6 +53,13 @@ it { is_expected.to be response } end + + context 'when response status is 401' do + let(:status) { 401 } + let(:response) { I18n.t('exercises.export_codeharbor.not_authorized') } + + it { is_expected.to eql response } + end end context 'when an error occurs' do