1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

fixed error handling

This commit is contained in:
Fedor Katurov 2021-03-04 13:57:00 +07:00
parent b95d53791c
commit 0873e77ff4
5 changed files with 20 additions and 19 deletions

View file

@ -234,7 +234,7 @@ function* requestRestoreCode({ field }: ReturnType<typeof authRequestRestoreCode
yield put(authSetRestore({ is_loading: false, is_succesfull: true })); yield put(authSetRestore({ is_loading: false, is_succesfull: true }));
} catch (error) { } catch (error) {
return yield put(authSetRestore({ is_loading: false, error })); return yield put(authSetRestore({ is_loading: false, error: error.message }));
} }
} }
@ -251,7 +251,9 @@ function* showRestoreModal({ code }: ReturnType<typeof authShowRestoreModal>) {
yield put(authSetRestore({ user: data.user, code, is_loading: false })); yield put(authSetRestore({ user: data.user, code, is_loading: false }));
yield put(modalShowDialog(DIALOGS.RESTORE_PASSWORD)); yield put(modalShowDialog(DIALOGS.RESTORE_PASSWORD));
} catch (error) { } catch (error) {
yield put(authSetRestore({ is_loading: false, error: error || ERRORS.CODE_IS_INVALID })); yield put(
authSetRestore({ is_loading: false, error: error.message || ERRORS.CODE_IS_INVALID })
);
yield put(modalShowDialog(DIALOGS.RESTORE_PASSWORD)); yield put(modalShowDialog(DIALOGS.RESTORE_PASSWORD));
} }
} }
@ -276,7 +278,9 @@ function* restorePassword({ password }: ReturnType<typeof authRestorePassword>)
yield call(refreshUser); yield call(refreshUser);
} catch (error) { } catch (error) {
return yield put(authSetRestore({ is_loading: false, error: error || ERRORS.CODE_IS_INVALID })); return yield put(
authSetRestore({ is_loading: false, error: error.message || ERRORS.CODE_IS_INVALID })
);
} }
} }
@ -286,7 +290,7 @@ function* getSocials() {
const data: Unwrap<typeof apiGetSocials> = yield call(apiGetSocials); const data: Unwrap<typeof apiGetSocials> = yield call(apiGetSocials);
yield put(authSetSocials({ accounts: data.accounts })); yield put(authSetSocials({ accounts: data.accounts }));
} catch (error) { } catch (error) {
yield put(authSetSocials({ error })); yield put(authSetSocials({ error: error.message }));
} finally { } finally {
yield put(authSetSocials({ is_loading: false })); yield put(authSetSocials({ is_loading: false }));
} }
@ -303,7 +307,7 @@ function* dropSocial({ provider, id }: ReturnType<typeof authDropSocial>) {
yield call(getSocials); yield call(getSocials);
} catch (error) { } catch (error) {
yield put(authSetSocials({ error })); yield put(authSetSocials({ error: error.message }));
} }
} }
@ -355,7 +359,7 @@ function* loginWithSocial({ token }: ReturnType<typeof authLoginWithSocial>) {
return; return;
} }
} catch (error) { } catch (error) {
yield put(userSetLoginError(error)); yield put(userSetLoginError(error.message));
} }
} }
@ -400,7 +404,7 @@ function* authRegisterSocial({ username, password }: ReturnType<typeof authSendR
return; return;
} }
} catch (error) { } catch (error) {
yield put(authSetRegisterSocial({ error })); yield put(authSetRegisterSocial({ error: error.message }));
} }
} }

View file

@ -55,7 +55,7 @@ function* getMessages({ username }: ReturnType<typeof messagesGetMessages>) {
} }
} catch (error) { } catch (error) {
messagesSet({ messagesSet({
error: error || ERRORS.EMPTY_RESPONSE, error: error.message || ERRORS.EMPTY_RESPONSE,
}); });
} finally { } finally {
yield put( yield put(
@ -110,7 +110,7 @@ function* sendMessage({ message, onSuccess }: ReturnType<typeof messagesSendMess
onSuccess(); onSuccess();
} catch (error) { } catch (error) {
messagesSet({ messagesSet({
error: error || ERRORS.EMPTY_RESPONSE, error: error.message || ERRORS.EMPTY_RESPONSE,
}); });
} finally { } finally {
yield put( yield put(
@ -155,7 +155,7 @@ function* deleteMessage({ id, is_locked }: ReturnType<typeof messagesDeleteMessa
); );
} catch (error) { } catch (error) {
messagesSet({ messagesSet({
error: error || ERRORS.EMPTY_RESPONSE, error: error.message || ERRORS.EMPTY_RESPONSE,
}); });
} finally { } finally {
yield put( yield put(
@ -193,7 +193,7 @@ function* refreshMessages({}: ReturnType<typeof messagesRefreshMessages>) {
yield put(messagesSet({ messages: newMessages })); yield put(messagesSet({ messages: newMessages }));
} catch (error) { } catch (error) {
messagesSet({ messagesSet({
error: error || ERRORS.EMPTY_RESPONSE, error: error.message || ERRORS.EMPTY_RESPONSE,
}); });
} finally { } finally {
yield put( yield put(

View file

@ -99,7 +99,7 @@ function* onNodeSave({ node }: ReturnType<typeof nodeSave>) {
return yield put(modalSetShown(false)); return yield put(modalSetShown(false));
} catch (error) { } catch (error) {
yield put(nodeSetSaveErrors({ error: error || ERRORS.CANT_SAVE_NODE })); yield put(nodeSetSaveErrors({ error: error.message || ERRORS.CANT_SAVE_NODE }));
} }
} }
@ -214,7 +214,7 @@ function* onPostComment({ nodeId, comment, callback }: ReturnType<typeof nodePos
callback(); callback();
} }
} catch (error) { } catch (error) {
return callback(error); return callback(error.message);
} }
} }

View file

@ -131,15 +131,12 @@ export function configureStore(): {
}); });
// Logout on 401 // Logout on 401
api.interceptors.response.use(undefined, (error: AxiosError<{ message: string }>) => { api.interceptors.response.use(undefined, (error: AxiosError<{ error: string }>) => {
if (error.response?.status === 401) { if (error.response?.status === 401) {
store.dispatch(authLogout()); store.dispatch(authLogout());
} }
console.log('Вот что случилось на сервере:', error); throw new Error(error?.response?.data?.error || error?.message || error?.response?.statusText);
throw new Error(
error?.response?.data?.message || error?.message || error?.response?.statusText
);
}); });
return { store, persistor }; return { store, persistor };

View file

@ -133,7 +133,7 @@ function* uploadFile({ file, temp_id, type, target, onSuccess, onFail }: IFileWi
return yield put( return yield put(
uploadSetStatus(temp_id, { uploadSetStatus(temp_id, {
is_uploading: false, is_uploading: false,
error, error: error.message,
type, type,
}) })
); );