Merge pull request #2378 from dataquest-dev/show_password_error

Show error message from the password validation response
This commit is contained in:
Alan Orth
2023-08-04 15:21:08 +03:00
committed by GitHub

View File

@@ -161,7 +161,7 @@ export class ProfilePageComponent implements OnInit {
} else { } else {
this.notificationsService.error( this.notificationsService.error(
this.translate.instant(this.PASSWORD_NOTIFICATIONS_PREFIX + 'error.title'), this.translate.instant(this.PASSWORD_NOTIFICATIONS_PREFIX + 'error.title'),
this.translate.instant(this.PASSWORD_NOTIFICATIONS_PREFIX + 'error.change-failed') this.getPasswordErrorMessage(response)
); );
} }
}); });
@@ -199,4 +199,18 @@ export class ProfilePageComponent implements OnInit {
return this.isResearcherProfileEnabled$.asObservable(); return this.isResearcherProfileEnabled$.asObservable();
} }
/**
* Returns an error message from a password validation request with a specific reason or
* a default message without specific reason.
* @param response from the validation password patch request.
*/
getPasswordErrorMessage(response) {
if (response.hasFailed && isNotEmpty(response.errorMessage)) {
// Response has a specific error message. Show this message in the error notification.
return this.translate.instant(response.errorMessage);
}
// Show default error message notification.
return this.translate.instant(this.PASSWORD_NOTIFICATIONS_PREFIX + 'error.change-failed');
}
} }