error handling for ENOENT in parse

merge-requests/1/merge
Matthew 2019-11-11 21:00:41 -05:00
parent ba3fd31c8e
commit 7c4ca745ac
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
1 changed files with 7 additions and 1 deletions

View File

@ -18,7 +18,13 @@ export default class Parse extends Command {
if (!args.length) return this.client.commands.get('help').run(message, [this.name]); if (!args.length) return this.client.commands.get('help').run(message, [this.name]);
const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0].replace(/[<@!>]/gi, '') }] }); const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0].replace(/[<@!>]/gi, '') }] });
if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot find user.***`); if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot find user.***`);
const dir = await fs.readdir(`/home/${account.username}/Validation`); let dir: string[];
try {
dir = await fs.readdir(`/home/${account.username}/Validation`);
} catch (err) {
return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot locate Validation directory.***`);
}
if (!dir.length) return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot locate certificate.***`);
const cert = parseCert(`/home/${account.username}/Validation/${dir[0]}`); const cert = parseCert(`/home/${account.username}/Validation/${dir[0]}`);
const subjectCommonName = cert.subject.commonName ? cert.subject.commonName : 'Not Specified'; const subjectCommonName = cert.subject.commonName ? cert.subject.commonName : 'Not Specified';
const subjectEmailAddress = cert.subject.emailAddress ? cert.subject.emailAddress : 'Not Specified'; const subjectEmailAddress = cert.subject.emailAddress ? cert.subject.emailAddress : 'Not Specified';