Prevent HTTP 500 when the server can't load the word list
This commit is contained in:
parent
646960759e
commit
c62907102c
1 changed files with 6 additions and 1 deletions
|
|
@ -28,7 +28,12 @@ const route: ServerRoute = {
|
|||
if (config.game.files[word_list] == null) {
|
||||
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();
|
||||
|
||||
log.info(`New game in ${channel} with answer: ${phrase}`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue