mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
fixed error handling on profile
This commit is contained in:
parent
0873e77ff4
commit
27665c462a
2 changed files with 8 additions and 10 deletions
|
@ -50,14 +50,13 @@ import {
|
||||||
selectAuthUser,
|
selectAuthUser,
|
||||||
} from './selectors';
|
} from './selectors';
|
||||||
import { OAUTH_EVENT_TYPES, Unwrap } from '../types';
|
import { OAUTH_EVENT_TYPES, Unwrap } from '../types';
|
||||||
import { IAuthState } from './types';
|
|
||||||
import { REHYDRATE, RehydrateAction } from 'redux-persist';
|
import { REHYDRATE, RehydrateAction } from 'redux-persist';
|
||||||
import { selectModal } from '~/redux/modal/selectors';
|
import { selectModal } from '~/redux/modal/selectors';
|
||||||
import { IModalState } from '~/redux/modal';
|
|
||||||
import { DIALOGS } from '~/redux/modal/constants';
|
import { DIALOGS } from '~/redux/modal/constants';
|
||||||
import { ERRORS } from '~/constants/errors';
|
import { ERRORS } from '~/constants/errors';
|
||||||
import { messagesSet } from '~/redux/messages/actions';
|
import { messagesSet } from '~/redux/messages/actions';
|
||||||
import { SagaIterator } from 'redux-saga';
|
import { SagaIterator } from 'redux-saga';
|
||||||
|
import { isEmpty } from 'ramda';
|
||||||
|
|
||||||
function* setTokenSaga({ token }: ReturnType<typeof authSetToken>) {
|
function* setTokenSaga({ token }: ReturnType<typeof authSetToken>) {
|
||||||
localStorage.setItem('token', token);
|
localStorage.setItem('token', token);
|
||||||
|
@ -207,19 +206,16 @@ function* patchUser(payload: ReturnType<typeof authPatchUser>) {
|
||||||
const me: ReturnType<typeof selectAuthUser> = yield select(selectAuthUser);
|
const me: ReturnType<typeof selectAuthUser> = yield select(selectAuthUser);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { user, errors }: Unwrap<typeof apiUpdateUser> = yield call(apiUpdateUser, {
|
const { user }: Unwrap<typeof apiUpdateUser> = yield call(apiUpdateUser, {
|
||||||
user: payload.user,
|
user: payload.user,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (errors && Object.keys(errors).length) {
|
|
||||||
yield put(authSetProfile({ patch_errors: errors }));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
yield put(authSetUser({ ...me, ...user }));
|
yield put(authSetUser({ ...me, ...user }));
|
||||||
yield put(authSetProfile({ user: { ...me, ...user }, tab: 'profile' }));
|
yield put(authSetProfile({ user: { ...me, ...user }, tab: 'profile' }));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return;
|
if (isEmpty(error.response.data.errors)) return;
|
||||||
|
|
||||||
|
yield put(authSetProfile({ patch_errors: error.response.data.errors }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,9 @@ export function configureStore(): {
|
||||||
store.dispatch(authLogout());
|
store.dispatch(authLogout());
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(error?.response?.data?.error || error?.message || error?.response?.statusText);
|
error.message = error?.response?.data?.error || error?.response?.statusText || error.message;
|
||||||
|
|
||||||
|
throw error;
|
||||||
});
|
});
|
||||||
|
|
||||||
return { store, persistor };
|
return { store, persistor };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue