fix(ui): reset password handle error and display

This commit is contained in:
Shekar Siri 2024-11-06 16:30:29 +01:00
parent d47491f989
commit 06667df5cd
3 changed files with 18 additions and 9 deletions

View file

@ -38,7 +38,6 @@ function ResetPasswordRequest() {
setRequested(true);
if (response && response.errors && response.errors.length > 0) {
setError(response.errors[0]);
} else {
}
});
};

View file

@ -411,10 +411,13 @@ class UserStore {
this.loading = true;
});
try {
await userService.requestResetPassword(params);
const response = await userService.requestResetPassword(params);
if (response.errors) {
toast.error(response.errors[0] || 'Error resetting your password, please try again');
return response;
}
} catch (error) {
toast.error('Error resetting your password; please try again');
return error.response;
toast.error('Unexpected error resetting your password; please try again');
} finally {
runInAction(() => {
this.loading = false;

View file

@ -143,11 +143,18 @@ export default class UserService {
.then((response: { data: any }) => response.data || {});
}
requestResetPassword(data: any) {
return this.client
.post('/password/reset-link', data)
.then((response: { json: () => any }) => response.json())
.then((response: { data: any }) => response.data || {});
async requestResetPassword(data: any) {
try {
const response = await this.client.post('/password/reset-link', data);
const responseData = await response.json();
return responseData.data || {};
} catch (error: any) {
if (error.response) {
const errorData = await error.response.json();
return { errors: errorData.errors };
}
return { errors: ["An unexpected error occurred."] };
}
}
updatePassword(data: any) {