Skip to content

Commit

Permalink
Update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Freeassassin committed Aug 15, 2023
1 parent 3f12df5 commit c6739f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
22 changes: 4 additions & 18 deletions client/src/state/user/saga.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,9 @@ export function* loginSaga({ payload: { setSnackbar, setIsLoading, email, passwo
const result = yield call(axios.post, '/user/login', { email, password });
yield put(loginSuccess(result.data.user));
} catch (error) {
setSnackbar(
error.response?.data?.message
? error.response?.data?.message.toString()
: error.response?.data
? error.response?.data.toString()
: error.toString(),
true,
);
setSnackbar(error.response?.data?.errorMessage, true);
setIsLoading(false);
yield put(loginFail(error.response.data));
yield put(loginFail(error.response?.data?.errorMessage));
}
}

Expand Down Expand Up @@ -110,16 +103,9 @@ export function* createUserSaga({ payload: { setSnackbar, setIsLoading, user } }
const result = yield call(axios.post, '/user/signup', user);
yield put(signupSuccess(result.data.user));
} catch (error) {
setSnackbar(
error.response?.data?.message
? error.response?.data?.message.toString()
: error.response?.data
? error.response?.data.toString()
: error.toString(),
true,
);
setSnackbar(error.response?.data?.errorMessage, true);
setIsLoading(false);
yield put(signupFail(error.response.data));
yield put(signupFail(error.response?.data?.errorMessage));
}
}

Expand Down
6 changes: 4 additions & 2 deletions server/src/controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ const UserController = {
passport.authenticate('local', (err, user) => {
if (err || !user) {
//req.log.info("Incorrect Email and Password entered by user");
res.status(403).send({ message: 'Please ensure your email and password are correct.' });
res
.status(403)
.send({ errorMessage: 'Please ensure your email and password are correct.' });
} else if (!user.confirmedEmail) {
// req.log.error(err, "Attempt to login with unverified email");
res.status(403).send({ message: 'Please ensure that you have verified your email.' });
res.status(403).send({ errorMessage: 'Please ensure that you have verified your email.' });
} else {
req.logIn(user, (err) => {
if (err) {
Expand Down

0 comments on commit c6739f8

Please sign in to comment.