Skip to content

Commit e6546b4

Browse files
committed
Show error message from the error response
1 parent db6edbf commit e6546b4

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/app/profile-page/profile-page.component.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class ProfilePageComponent implements OnInit {
161161
} else {
162162
this.notificationsService.error(
163163
this.translate.instant(this.PASSWORD_NOTIFICATIONS_PREFIX + 'error.title'),
164-
this.translate.instant(this.PASSWORD_NOTIFICATIONS_PREFIX + 'error.change-failed')
164+
this.getPasswordErrorMessage(response)
165165
);
166166
}
167167
});
@@ -199,4 +199,18 @@ export class ProfilePageComponent implements OnInit {
199199
return this.isResearcherProfileEnabled$.asObservable();
200200
}
201201

202+
/**
203+
* Returns an error message from a password validation request with a specific reason or
204+
* a default message without specific reason.
205+
* @param response from the validation password patch request.
206+
*/
207+
getPasswordErrorMessage(response) {
208+
if (response.hasFailed && isNotEmpty(response.errorMessage)) {
209+
// Response has a specific error message. Show this message in the error notification.
210+
return this.translate.instant(response.errorMessage);
211+
}
212+
// Show default error message notification.
213+
return this.translate.instant(this.PASSWORD_NOTIFICATIONS_PREFIX + 'error.change-failed');
214+
}
215+
202216
}

0 commit comments

Comments
 (0)