Skip to content

Commit 0f59bfc

Browse files
committed
1680: Improve error when exporting through an account_link
1 parent 5cb21f1 commit 0f59bfc

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

app/services/task_service/push_external.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ def execute
1212
body = @zip.string
1313
begin
1414
response = connection.post {|request| request_parameters(request, body) }
15-
response.success? ? nil : response.body
15+
if response.success?
16+
nil
17+
else
18+
response.status == 401 ? I18n.t('tasks.export_external_confirm.not_authorized', account_link: @account_link.name) : response.body
19+
end
1620
rescue StandardError => e
1721
e
1822
end

config/locales/de/controllers/tasks.yml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ de:
88
error_alert: Die Aufgabe konnte nicht dupliziert werden.
99
export_external_confirm:
1010
error: 'Der Export der Aufgabe (%{title}) ist fehlgeschlagen. <br> Fehler: %{error}'
11+
not_authorized: Die Autorisierung mit "%{account_link}" konnte nicht hergestellt werden. Ist der API-Schlüssel korrekt?
1112
success: Aufgabe (%{title}) erfolgreich exportiert.
1213
import:
1314
internal_error: Beim Import dieser Aufgabe ist auf CodeHarbor ein interner Fehler aufgetreten.

config/locales/en/controllers/tasks.yml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ en:
88
error_alert: Task could not be duplicated
99
export_external_confirm:
1010
error: 'Export of task (%{title}) failed. <br> Error: %{error}'
11+
not_authorized: Authorization with could not be established with "%{account_link}". Is the API Key correct?
1112
success: Task (%{title}) successfully exported.
1213
import:
1314
internal_error: An internal error occurred on CodeHarbor while importing the exercise.

spec/services/task_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('tasks.export_external_confirm.not_authorized', account_link: account_link.name) }
60+
61+
it { is_expected.to eq response }
62+
end
5663
end
5764

5865
context 'when an error occurs' do

0 commit comments

Comments
 (0)