0
0
Fork 0

Prevent HTTP 500 when the server can't load the word list

This commit is contained in:
Oliver-Akins 2023-08-27 19:27:44 -06:00
parent 646960759e
commit c62907102c

View file

@ -28,7 +28,12 @@ const route: ServerRoute = {
if (config.game.files[word_list] == null) { if (config.game.files[word_list] == null) {
throw boom.notAcceptable(`Invalid word list`); throw boom.notAcceptable(`Invalid word list`);
}; };
let phrases = readFileSync(config.game.files[word_list] as string, `utf-8`).split(`\n`); let phrases: string[];
try {
phrases = readFileSync(config.game.files[word_list] as string, `utf-8`).split(`\n`);
} catch {
return `Couldn't load word list "${word_list}", please try a different one`;
};
let phrase = phrases[Math.floor(Math.random() * phrases.length)].trim(); let phrase = phrases[Math.floor(Math.random() * phrases.length)].trim();
log.info(`New game in ${channel} with answer: ${phrase}`); log.info(`New game in ${channel} with answer: ${phrase}`);