From f746d45ac153f64c27a5e080083f11137dd1dccf Mon Sep 17 00:00:00 2001 From: milanmajchrak Date: Thu, 20 Jul 2023 12:46:30 +0200 Subject: [PATCH] Show error message from the error response (cherry picked from commit e6546b4499fe87a9308dab7ff2c6767f9f256c67) --- src/app/profile-page/profile-page.component.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/app/profile-page/profile-page.component.ts b/src/app/profile-page/profile-page.component.ts index 343314999ba..d49bdedb838 100644 --- a/src/app/profile-page/profile-page.component.ts +++ b/src/app/profile-page/profile-page.component.ts @@ -161,7 +161,7 @@ export class ProfilePageComponent implements OnInit { } else { this.notificationsService.error( 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(); } + /** + * 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'); + } + }