diff --git a/src/redux/auth/sagas.ts b/src/redux/auth/sagas.ts index 8b3ba089..728677d9 100644 --- a/src/redux/auth/sagas.ts +++ b/src/redux/auth/sagas.ts @@ -50,14 +50,13 @@ import { selectAuthUser, } from './selectors'; import { OAUTH_EVENT_TYPES, Unwrap } from '../types'; -import { IAuthState } from './types'; import { REHYDRATE, RehydrateAction } from 'redux-persist'; import { selectModal } from '~/redux/modal/selectors'; -import { IModalState } from '~/redux/modal'; import { DIALOGS } from '~/redux/modal/constants'; import { ERRORS } from '~/constants/errors'; import { messagesSet } from '~/redux/messages/actions'; import { SagaIterator } from 'redux-saga'; +import { isEmpty } from 'ramda'; function* setTokenSaga({ token }: ReturnType) { localStorage.setItem('token', token); @@ -207,19 +206,16 @@ function* patchUser(payload: ReturnType) { const me: ReturnType = yield select(selectAuthUser); try { - const { user, errors }: Unwrap = yield call(apiUpdateUser, { + const { user }: Unwrap = yield call(apiUpdateUser, { user: payload.user, }); - if (errors && Object.keys(errors).length) { - yield put(authSetProfile({ patch_errors: errors })); - return; - } - yield put(authSetUser({ ...me, ...user })); yield put(authSetProfile({ user: { ...me, ...user }, tab: 'profile' })); } catch (error) { - return; + if (isEmpty(error.response.data.errors)) return; + + yield put(authSetProfile({ patch_errors: error.response.data.errors })); } } diff --git a/src/redux/store.ts b/src/redux/store.ts index 61e2393e..eb9c60ff 100644 --- a/src/redux/store.ts +++ b/src/redux/store.ts @@ -136,7 +136,9 @@ export function configureStore(): { 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 };