Skip to content
Snippets Groups Projects
Commit 78794fce authored by michael.minelli's avatar michael.minelli
Browse files

DojoBackendManager => Add some api error handler

parent ac9581e4
Branches
Tags
No related merge requests found
......@@ -10,6 +10,7 @@ import User from '../sharedByClients/models/User';
import DojoStatusCode from '../shared/types/Dojo/DojoStatusCode';
import * as Gitlab from '@gitbeaker/rest';
import DojoBackendHelper from '../sharedByClients/helpers/Dojo/DojoBackendHelper';
import GitlabPipelineStatus from '../shared/types/Gitlab/GitlabPipelineStatus';
class DojoBackendManager {
......@@ -20,20 +21,29 @@ class DojoBackendManager {
case DojoStatusCode.ASSIGNMENT_EXERCISE_NOT_RELATED:
spinner.fail(`The exercise does not belong to the assignment.`);
break;
case DojoStatusCode.ASSIGNMENT_PUBLISH_NO_PIPELINE:
spinner.fail(`No pipeline found for this assignment.`);
break;
case DojoStatusCode.ASSIGNMENT_PUBLISH_PIPELINE_FAILED:
spinner.fail(error.response?.data?.message ?? `Last pipeline status is not "${ GitlabPipelineStatus.SUCCESS }".`);
break;
case DojoStatusCode.EXERCISE_CORRECTION_ALREADY_EXIST:
spinner.fail(`This exercise is already labelled as a correction. If you want to update it, please use the update command.`);
break;
case DojoStatusCode.EXERCISE_CORRECTION_NOT_EXIST:
spinner.fail(`The exercise is not labelled as a correction so it's not possible to update it.`);
break;
case DojoStatusCode.ASSIGNMENT_CREATION_GITLAB_ERROR:
spinner.fail(`Assignment creation error: An unknown error occurred while creating the assignment on Gitlab. Please try again later or contact an administrator.`);
case DojoStatusCode.ASSIGNMENT_NAME_CONFLICT:
spinner.fail(`Assignment creation error: The assignment name already exists. Please choose another name.`);
break;
case DojoStatusCode.ASSIGNMENT_CREATION_ERROR:
spinner.fail(`Assignment creation error: An unknown error occurred while creating the assignment (internal error message: ${ error.response?.data?.description ?? 'unknown error' }). Please try again later or contact an administrator.`);
break;
case DojoStatusCode.MAX_EXERCISE_PER_ASSIGNMENT_REACHED:
spinner.fail(`The following users have reached the maximum number of exercise of this assignment : ${ ((error.response.data as DojoBackendResponse<Array<Gitlab.UserSchema>>).data).map(user => user.name).join(', ') }.`);
break;
case DojoStatusCode.EXERCISE_CREATION_GITLAB_ERROR:
spinner.fail(`Exercise creation error: An unknown error occurred while creating the exercise on Gitlab. Please try again later or contact an administrator.`);
case DojoStatusCode.EXERCISE_CREATION_ERROR:
spinner.fail(`Exercise creation error: An unknown error occurred while creating the exercise (internal error message: ${ error.response?.data?.description ?? 'unknown error' }). Please try again later or contact an administrator.`);
break;
case DojoStatusCode.GITLAB_TEMPLATE_NOT_FOUND:
spinner.fail(`Template not found or access denied. Please check the template ID or url. Also, please check that the template have public/internal visibility or that your and Dojo account (${ ClientsSharedConfig.gitlab.dojoAccount.username }) have at least reporter role to the template (if private).`);
......@@ -169,13 +179,7 @@ class DojoBackendManager {
return;
} catch ( error ) {
if ( verbose ) {
if ( error instanceof AxiosError && error.response ) {
spinner.fail(`Assignment visibility change error: ${ error.response.statusText }`);
} else {
spinner.fail(`Assignment visibility change error: unknown error`);
}
}
this.handleApiError(error, spinner, verbose, `Assignment visibility change error: ${ error }`);
throw error;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment