use appError on socket io

This commit is contained in:
canove
2020-09-20 10:52:05 -03:00
parent b7484afd63
commit aa6f116514
2 changed files with 112 additions and 111 deletions

View File

@@ -1,5 +1,6 @@
import socketIo, { Server as SocketIO } from "socket.io"; import socketIo, { Server as SocketIO } from "socket.io";
import { Server } from "http"; import { Server } from "http";
import AppError from "../errors/AppError";
let io: SocketIO; let io: SocketIO;
@@ -9,7 +10,7 @@ export const initIO = (httpServer: Server): SocketIO => {
}; };
export const getIO = (): SocketIO => { export const getIO = (): SocketIO => {
if (!io) { if (!io) {
throw new Error("Socket IO not initialized"); throw new AppError("Socket IO not initialized");
} }
return io; return io;
}; };

View File

@@ -24,7 +24,7 @@ module.exports = {
const wbot = new Client({ const wbot = new Client({
session: sessionCfg, session: sessionCfg,
restartOnAuthFail: true, restartOnAuthFail: true
}); });
wbot.initialize(); wbot.initialize();
@@ -37,7 +37,7 @@ module.exports = {
io.emit("whatsappSession", { io.emit("whatsappSession", {
action: "update", action: "update",
session: whatsapp, session: whatsapp
}); });
}); });
@@ -46,12 +46,12 @@ module.exports = {
await whatsapp.update({ await whatsapp.update({
session: JSON.stringify(session), session: JSON.stringify(session),
status: "authenticated", status: "authenticated"
}); });
io.emit("whatsappSession", { io.emit("whatsappSession", {
action: "update", action: "update",
session: whatsapp, session: whatsapp
}); });
}); });
@@ -66,12 +66,12 @@ module.exports = {
await whatsapp.update({ await whatsapp.update({
status: "CONNECTED", status: "CONNECTED",
qrcode: "", qrcode: ""
}); });
io.emit("whatsappSession", { io.emit("whatsappSession", {
action: "update", action: "update",
session: whatsapp, session: whatsapp
}); });
wbot.sendPresenceAvailable(); wbot.sendPresenceAvailable();
@@ -106,5 +106,5 @@ module.exports = {
} catch (err) { } catch (err) {
console.log(err); console.log(err);
} }
}, }
}; };