mirror of
https://github.com/AlecM33/Werewolf.git
synced 2025-12-26 15:57:50 +01:00
add some error handling
This commit is contained in:
@@ -26,12 +26,18 @@ class EventManager {
|
||||
|
||||
createRedisPublisher = async () => {
|
||||
this.publisher = redis.createClient();
|
||||
this.publisher.on('error', (e) => {
|
||||
this.logger.error('REDIS PUBLISHER CLIENT ERROR:', e);
|
||||
});
|
||||
await this.publisher.connect();
|
||||
this.logger.info('EVENT MANAGER - CREATED PUBLISHER');
|
||||
}
|
||||
|
||||
createGameSyncSubscriber = async (gameManager, eventManager) => {
|
||||
this.subscriber = this.client.duplicate();
|
||||
this.subscriber.on('error', (e) => {
|
||||
this.logger.error('REDIS SUBSCRIBER CLIENT ERROR:', e);
|
||||
});
|
||||
await this.subscriber.connect();
|
||||
await this.subscriber.subscribe(globals.REDIS_CHANNELS.ACTIVE_GAME_STREAM, async (message) => {
|
||||
this.logger.debug('MESSAGE: ' + message);
|
||||
@@ -46,8 +52,8 @@ class EventManager {
|
||||
message.slice(
|
||||
message.indexOf(messageComponents[messageComponents.length - 1]) + (globals.INSTANCE_ID_LENGTH + 1)
|
||||
)
|
||||
)
|
||||
} catch(e) {
|
||||
);
|
||||
} catch (e) {
|
||||
this.logger.error('MALFORMED MESSAGE RESULTED IN ERROR: ' + e + '; DISREGARDING');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,15 @@ class GameManager {
|
||||
}
|
||||
delete this.timerManager.timerThreads[accessCode];
|
||||
}
|
||||
return r === null ? r : JSON.parse(r);
|
||||
let activeGame;
|
||||
if (r !== null) {
|
||||
try {
|
||||
activeGame = JSON.parse(r);
|
||||
} catch (e) {
|
||||
this.logger.error('ERROR PARSING ACTIVE GAME: ' + e);
|
||||
}
|
||||
}
|
||||
return r === null ? r : activeGame;
|
||||
}
|
||||
|
||||
setGameSocketNamespace = (namespace) => {
|
||||
@@ -62,8 +70,8 @@ class GameManager {
|
||||
moderator.assigned = true;
|
||||
if (req.timerParams !== null) {
|
||||
req.timerParams.paused = true;
|
||||
req.timerParams.timeRemaining = convertFromHoursToMilliseconds(req.timerParams.hours)
|
||||
+ convertFromMinutesToMilliseconds(req.timerParams.minutes);
|
||||
req.timerParams.timeRemaining = convertFromHoursToMilliseconds(req.timerParams.hours) +
|
||||
convertFromMinutesToMilliseconds(req.timerParams.minutes);
|
||||
}
|
||||
const newGame = new Game(
|
||||
newAccessCode,
|
||||
@@ -251,8 +259,8 @@ class GameManager {
|
||||
game.status = globals.STATUS.IN_PROGRESS;
|
||||
if (game.hasTimer) {
|
||||
game.timerParams.paused = true;
|
||||
game.timerParams.timeRemaining = convertFromHoursToMilliseconds(game.timerParams.hours)
|
||||
+ convertFromMinutesToMilliseconds(game.timerParams.minutes);
|
||||
game.timerParams.timeRemaining = convertFromHoursToMilliseconds(game.timerParams.hours) +
|
||||
convertFromMinutesToMilliseconds(game.timerParams.minutes);
|
||||
await this.timerManager.runTimer(game, namespace, this.eventManager, this);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user