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

HttpManager => Display general error only when there is no custom one

parent bc700eb0
No related branches found
No related tags found
No related merge requests found
Pipeline #30870 passed
...@@ -36,15 +36,21 @@ class DojoBackendManager { ...@@ -36,15 +36,21 @@ class DojoBackendManager {
case DojoStatusCode.ASSIGNMENT_NAME_CONFLICT: case DojoStatusCode.ASSIGNMENT_NAME_CONFLICT:
spinner.fail(`Assignment creation error: The assignment name already exists. Please choose another name.`); spinner.fail(`Assignment creation error: The assignment name already exists. Please choose another name.`);
break; break;
case DojoStatusCode.ASSIGNMENT_CREATION_ERROR: case DojoStatusCode.ASSIGNMENT_CREATION_GITLAB_ERROR:
spinner.fail(`Assignment creation error: An unknown error occurred while creating the assignment on GitLab (internal error message: ${ error.response?.data?.description ?? 'unknown error' }). Please try again later or contact an administrator.`);
break;
case DojoStatusCode.ASSIGNMENT_CREATION_INTERNAL_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.`); 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; break;
case DojoStatusCode.MAX_EXERCISE_PER_ASSIGNMENT_REACHED: 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(', ') }.`); 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; break;
case DojoStatusCode.EXERCISE_CREATION_ERROR: case DojoStatusCode.EXERCISE_CREATION_INTERNAL_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.`); 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; break;
case DojoStatusCode.EXERCISE_CREATION_GITLAB_ERROR:
spinner.fail(`Exercise creation error: An unknown error occurred while creating the exercise on GitLab (internal error message: ${ error.response?.data?.description ?? 'unknown error' }). Please try again later or contact an administrator.`);
break;
case DojoStatusCode.GITLAB_TEMPLATE_NOT_FOUND: 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).`); 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).`);
break; break;
......
...@@ -76,16 +76,20 @@ class HttpManager { ...@@ -76,16 +76,20 @@ class HttpManager {
private apiAuthorizationError(error: AxiosError, isFromApi: boolean) { private apiAuthorizationError(error: AxiosError, isFromApi: boolean) {
if ( this.handleAuthorizationCommandErrors && isFromApi && error.response ) { if ( this.handleAuthorizationCommandErrors && isFromApi && error.response ) {
switch ( error.response.status ) { const errorCustomCode = (error.response.data as DojoBackendResponse<unknown> | undefined)?.code ?? error.response.status;
case StatusCodes.UNAUTHORIZED:
this.requestError('Session expired or does not exist. Please login again.'); if ( errorCustomCode === error.response.status ) {
break; switch ( error.response.status ) {
case StatusCodes.FORBIDDEN: case StatusCodes.UNAUTHORIZED:
this.requestError('Forbidden access.'); this.requestError('Session expired or does not exist. Please login again.');
break; break;
default: case StatusCodes.FORBIDDEN:
this.requestError('Unknown error.'); this.requestError('Forbidden access.');
break; break;
default:
this.requestError('Unknown error.');
break;
}
} }
} else { } else {
this.handleAuthorizationCommandErrors = true; this.handleAuthorizationCommandErrors = true;
......
Subproject commit 47b289f99ef88df993f5977efa6a53e4bd0abe85 Subproject commit 556a235605ba36ea775cd54da4aee8a5bc03d912
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment