Testing my code is essential, but I want to ensure that any errors are caught and handled properly. This is achieved by structuring my code in a way that prevents it from reaching the catch condition.
This is made possible by using a throw condition for the Promise. The handling of this promise is done in another file, ensuring that errors can be managed effectively.
export const userExists = async (name, phone) => {
try {
const userExists = await Promise.all([User.findOne({ name}), User.findOne({ phone})]);
if (userExists.some(el => !!el)) return true;
else return false;
} catch (error) {
return error;
}
};