advanced error handling™
This commit is contained in:
parent
6885508e01
commit
09bb65a4d2
|
@ -62,6 +62,7 @@ export default class slack extends EventEmitter {
|
||||||
setInterval(async () => await this.ping(), 3e4); // 30 seconds lul
|
setInterval(async () => await this.ping(), 3e4); // 30 seconds lul
|
||||||
|
|
||||||
this.server.wss.socket.on("data", async data => {
|
this.server.wss.socket.on("data", async data => {
|
||||||
|
try {
|
||||||
data = data.toString("utf-8").replace(/\0/g, "");
|
data = data.toString("utf-8").replace(/\0/g, "");
|
||||||
data = JSON.parse(data.substr(data.indexOf("{")));
|
data = JSON.parse(data.substr(data.indexOf("{")));
|
||||||
|
|
||||||
|
@ -70,10 +71,13 @@ export default class slack extends EventEmitter {
|
||||||
if(data.type !== "message")
|
if(data.type !== "message")
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
await Promise.all([this.getChannel(data.channel), this.getUser(data.user)]).catch(err => this.emit("data", [ "error", err ]));
|
await Promise.all([this.getChannel(data.channel), this.getUser(data.user)]);
|
||||||
//await this.getUser(data.user).catch(err => this.emit("data", [ "error", err ]));
|
|
||||||
|
|
||||||
return this.emit("data", [ "message", this.reply(data) ]);
|
return this.emit("data", [ "message", this.reply(data) ]);
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
this.emit("data", [ "error", err ]);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.on("end", () => this.emit("data", [ "debug", "stream ended" ]))
|
.on("end", () => this.emit("data", [ "debug", "stream ended" ]))
|
||||||
.on("error", err => this.emit("data", [ "error", err ]));
|
.on("error", err => this.emit("data", [ "error", err ]));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user