Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1680: Improve error when exporting through an account_link #2756

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
MrSerth marked this conversation as resolved.
Show resolved Hide resolved
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
Loading