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

@@ -1,6 +1,6 @@
import { Request, Response } from "express";
import { getIO } from "../libs/socket";
import { initWbot } from "../libs/wbot";
import { initWbot, removeWbot } from "../libs/wbot";
import wbotMessageListener from "../services/WbotServices/wbotMessageListener";
import wbotMonitor from "../services/WbotServices/wbotMonitor";
@@ -33,10 +33,6 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
const whatsapp = await CreateWhatsAppService({ name, status, isDefault });
// if (!whatsapp) {
// return res.status(400).json({ error: "Cannot create whatsapp session." });
// }
initWbot(whatsapp)
.then(() => {
wbotMessageListener(whatsapp);
@@ -70,14 +66,6 @@ export const update = async (
const whatsapp = await UpdateWhatsAppService({ whatsappData, whatsappId });
// const whatsapp = await Whatsapp.findByPk(whatsappId);
// if (!whatsapp) {
// return res.status(404).json({ message: "Whatsapp not found" });
// }
// await whatsapp.update(req.body);
const io = getIO();
io.emit("whatsapp", {
action: "update",
@@ -94,7 +82,7 @@ export const remove = async (
const { whatsappId } = req.params;
await DeleteWhatsAppService(whatsappId);
// removeWbot(whatsapp.id);
removeWbot(+whatsappId);
const io = getIO();
io.emit("whatsapp", {