fix: handling wwebjs erros without blocking routes

This commit is contained in:
canove
2020-09-22 16:33:13 -03:00
parent 0d8b4cd60c
commit 5c7a759efa
7 changed files with 80 additions and 74 deletions

View File

@@ -13,16 +13,19 @@ const ImportContactsService = async (): Promise<void> => {
try {
phoneContacts = await wbot.getContacts();
} catch (err) {
throw new AppError(
"Could not check whatsapp contact. Check connection page."
console.log(
"Could not get whatsapp contacts from phone. Check connection page.",
err
);
}
await Promise.all(
phoneContacts.map(async ({ number, name }) => {
await Contact.create({ number, name });
})
);
if (phoneContacts) {
await Promise.all(
phoneContacts.map(async ({ number, name }) => {
await Contact.create({ number, name });
})
);
}
};
export default ImportContactsService;