diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index ecbbd47..43e8c06 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -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); } }); @@ -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); } }); diff --git a/users/userservice/user-controller.js b/users/userservice/user-controller.js index 3aeb36b..efa64fa 100644 --- a/users/userservice/user-controller.js +++ b/users/userservice/user-controller.js @@ -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 }); + } }; diff --git a/webapp/src/pages/AddUser.jsx b/webapp/src/pages/AddUser.jsx index a0df33b..7b94247 100644 --- a/webapp/src/pages/AddUser.jsx +++ b/webapp/src/pages/AddUser.jsx @@ -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'); } };