Show error message from the error response

This commit is contained in:
milanmajchrak
2023-07-20 12:46:30 +02:00
parent db6edbf184
commit e6546b4499

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');
}
} }