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 { Server } from "http";
import AppError from "../errors/AppError";
let io: SocketIO;
@@ -9,7 +10,7 @@ export const initIO = (httpServer: Server): SocketIO => {
};
export const getIO = (): SocketIO => {
if (!io) {
throw new Error("Socket IO not initialized");
throw new AppError("Socket IO not initialized");
}
return io;
};

View File

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