Skip to content

Commit

Permalink
error msg fix (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
angelalvaigle committed Dec 16, 2024
1 parent 3795eb8 commit 9d2cdb5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 2 additions & 4 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ app.post('/adduser', async (req, res) => {
);
res.json(userResponse.data);
} catch (error) {
res
.status(error.response.status)
.json({ error: error.response.data.error });
res.status(error.response.status).json(error.response.data);
}
});

Expand Down Expand Up @@ -128,7 +126,7 @@ app.patch('/update-user', async (req, res) => {
);
res.json(userResponse.data);
} catch (error) {
res.status(error.response.status).json({ msg: error.response.data.msg });
res.status(error.response.status).json(error.response.data);
}
});

Expand Down
12 changes: 8 additions & 4 deletions users/userservice/user-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ export const getCurrentUserController = async (req, res) => {
};

export const updateUserController = async (req, res) => {
const newUser = { ...req.body };
delete newUser.password;
await User.findByIdAndUpdate(req.user.userId, newUser);
res.status(StatusCodes.OK).json({ msg: 'update user' });
try {
const newUser = { ...req.body };
delete newUser.password;
await User.findByIdAndUpdate(req.user.userId, newUser);
res.status(StatusCodes.OK).json({ msg: 'update user' });
} catch (error) {
res.status(500).json({ error: error.message });
}
};
2 changes: 1 addition & 1 deletion webapp/src/pages/AddUser.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const AddUser = () => {
navigate('/login');
}, 1000); // 1000 ms = 1 segundos
} catch (error) {
setError(error.response?.data?.error || 'An error occurred');
setError(error.response?.data?.msg || 'An error occurred');
}
};

Expand Down

0 comments on commit 9d2cdb5

Please sign in to comment.