Skip to content

Commit

Permalink
1680: Improve error when exporting through an account_link
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoehn committed Jan 29, 2025
1 parent fed3b13 commit a4f52e5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/services/exercise_service/push_external.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/locales/de/exercise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ de:
error: Es ist ein Fehler bei der Kommunikation mit CodeHarbor aufgetreten.
export_failed: 'Export ist fehlgeschlagen.<br>ID: %{id}<br>Title: %{title}<br><br>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.<br>ID: %{id}<br>Title: %{title}'
external_users:
statistics:
Expand Down
1 change: 1 addition & 0 deletions config/locales/en/exercise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ en:
error: An error occurred while contacting CodeHarbor
export_failed: 'Export has failed.<br>ID: %{id}<br>Title: %{title}<br><br>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.<br>ID: %{id}<br>Title: %{title}'
external_users:
statistics:
Expand Down
7 changes: 7 additions & 0 deletions spec/services/exercise_service/push_external_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a4f52e5

Please sign in to comment.