Add generic error catching to the event handling
This commit is contained in:
parent
f25d1ef965
commit
f2a0106c30
1 changed files with 12 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import { WebsocketEvent } from "./types/WebsocketEvent";
|
import { WebsocketEvent } from "./types/WebsocketEvent";
|
||||||
import { log, config } from "./main";
|
import { log, config } from "./main";
|
||||||
import { Server } from "socket.io";
|
import { Server } from "socket.io";
|
||||||
|
import { Status } from "common";
|
||||||
import glob from "glob";
|
import glob from "glob";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
|
|
@ -26,7 +27,17 @@ export default async function() {
|
||||||
for (var event of events) {
|
for (var event of events) {
|
||||||
socket.on(
|
socket.on(
|
||||||
event.name,
|
event.name,
|
||||||
(data: any) => event.handler(io, socket, data)
|
(data: any) => {
|
||||||
|
try {
|
||||||
|
event.handler(io, socket, data)
|
||||||
|
} catch (e) {
|
||||||
|
log.error(e);
|
||||||
|
socket.emit("res:error", {
|
||||||
|
status: Status.UnknownError,
|
||||||
|
message: "An unexpected error occured."
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue