Skip to content

Commit 741a6c7

Browse files
author
Mubashir Shariq
committed
correctly handling the error
1 parent 3846302 commit 741a6c7

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

server/controllers/user.controller.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,19 @@ const random = (done) => {
2929
});
3030
};
3131

32-
export function findUserByUsername(username, cb) {
33-
User.findByUsername(username, (err, user) => {
34-
cb(user);
35-
});
32+
export async function findUserByUsername(username) {
33+
try {
34+
const user = await User.findByUsername(username);
35+
return user;
36+
} catch (error) {
37+
// Handling the error appropriately, e.g., log the error, throw a custom error, etc.
38+
console.error('Error finding user by username:', error.message);
39+
throw new Error('Failed to find user by username');
40+
}
3641
}
3742

43+
44+
3845
export function createUser(req, res, next) {
3946
const { username, email } = req.body;
4047
const { password } = req.body;

0 commit comments

Comments
 (0)