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

Programming exercises: Display error message for unexpected errors on exercise import #8463

Closed
Show file tree
Hide file tree
Changes from 5 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { ProgrammingExerciseDifficultyComponent } from 'app/exercises/programmin
import { ProgrammingExerciseLanguageComponent } from 'app/exercises/programming/manage/update/update-components/programming-exercise-language.component';
import { ProgrammingExerciseGradingComponent } from 'app/exercises/programming/manage/update/update-components/programming-exercise-grading.component';
import { ExerciseUpdatePlagiarismComponent } from 'app/exercises/shared/plagiarism/exercise-update-plagiarism/exercise-update-plagiarism.component';
import { scrollToTopOfPage } from 'app/shared/util/utils';

export interface ImportOptions {
recreateBuildPlans: boolean;
Expand Down Expand Up @@ -674,6 +675,8 @@ export class ProgrammingExerciseUpdateComponent implements AfterViewInit, OnDest
private onSaveError(error: HttpErrorResponse) {
let errorMessage;
let disableTranslation;
let translationParams;

// Workaround for conflict error, since conflict errors do not have the 'X-artemisApp-alert' header
if (error.status === 409 && error.error && error.error['X-artemisApp-error'] === 'error.sourceExerciseInconsistent') {
errorMessage = 'artemisApp.consistencyCheck.error.programmingExerciseImportFailed';
Expand All @@ -682,13 +685,22 @@ export class ProgrammingExerciseUpdateComponent implements AfterViewInit, OnDest
errorMessage = error.headers.get('X-artemisApp-alert')!;
disableTranslation = true;
}

const errorMessageToBeTranslatedNotFound = !errorMessage;
if (errorMessageToBeTranslatedNotFound) {
errorMessage = `error.unexpectedError`;
translationParams = { error: error.statusText };
disableTranslation = false;
}

this.alertService.addAlert({
type: AlertType.DANGER,
message: errorMessage,
translationParams: translationParams,
disableTranslation: disableTranslation,
});
this.isSaving = false;
window.scrollTo(0, 0);
scrollToTopOfPage();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,36 @@ describe('ProgrammingExerciseUpdateComponent', () => {
expect(comp.isSaving).toBeFalse();
expect(alertSpy).toHaveBeenCalledWith({ type: AlertType.DANGER, message: 'error-message', disableTranslation: true });
});

it('should show alert for unknown error', async () => {
// GIVEN
const entity = new ProgrammingExercise(undefined, undefined);
entity.id = 1;
jest.spyOn(programmingExerciseService, 'update').mockReturnValue(
throwError(
new HttpResponse({
headers: new HttpHeaders(),
status: 500,
statusText: 'Internal Server Error',
}),
),
);
const alertSpy = jest.spyOn(alertService, 'addAlert');
comp.programmingExercise = entity;
comp.backupExercise = {} as ProgrammingExercise;
comp.programmingExercise.course = course;
// WHEN
comp.save();

// THEN
expect(comp.isSaving).toBeFalse();
expect(alertSpy).toHaveBeenCalledWith({
type: AlertType.DANGER,
message: 'error.unexpectedError',
translationParams: { error: 'Internal Server Error' },
disableTranslation: false,
});
});
});

describe('exam mode', () => {
Expand Down
Loading