diff --git a/src/commands/parse.ts b/src/commands/parse.ts index 5c1abf3..2bd957b 100644 --- a/src/commands/parse.ts +++ b/src/commands/parse.ts @@ -3,7 +3,7 @@ import { parseCert } from '@ghaiklor/x509'; import { Message } from 'eris'; import { Client } from '..'; import { Command, RichEmbed } from '../class'; -import { parseCertificate } from '../functions'; +import { parseCertificate, Certificate } from '../functions'; export default class Parse extends Command { constructor(client: Client) { @@ -26,7 +26,12 @@ export default class Parse extends Command { 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 = await parseCertificate(this.client, `${account.homepath}/Validation/${dir[0]}`); + let cert: Certificate; + try { + cert = await parseCertificate(this.client, `${account.homepath}/Validation/${dir[0]}`); + } catch (error) { + if (error.message.includes('panic: Certificate PEM Encode == nil')) return message.channel.createMessage(`***${this.client.stores.emojis.error} Invalid certificate.***`); + } // const cert = parseCert(`${account.homepath}/Validation/${dir[0]}`); const subjectCommonName = cert.subject.commonName || 'Not Specified'; const subjectEmailAddress = cert.subject.emailAddress || 'Not Specified'; diff --git a/src/commands/parseall.ts b/src/commands/parseall.ts index 999365b..b2a1cf0 100644 --- a/src/commands/parseall.ts +++ b/src/commands/parseall.ts @@ -48,6 +48,7 @@ export default class Parseall extends Command { else final.push(`${this.client.stores.emojis.success} **${a.username}** Expires in ${time}`); } catch (error) { if (error.message.includes('no such file or directory') || error.message.includes('File doesn\'t exist.')) final.push(`${this.client.stores.emojis.error} **${a.username}** Unable to locate certificate`); + if (error.message.includes('panic: Certificate PEM Encode == nil')) final.push(`${this.client.stores.emojis.error} ** ${a.username}** Invalid certificate`); else throw error; } }); diff --git a/src/functions/index.ts b/src/functions/index.ts index 4395294..bf1b87c 100644 --- a/src/functions/index.ts +++ b/src/functions/index.ts @@ -1,4 +1,4 @@ export { default as checkLock } from './checkLock'; export { default as dataConversion } from './dataConversion'; export { default as checkSS } from './checkSS'; -export { default as parseCertificate } from './parseCertificate'; +export { default as parseCertificate, Certificate } from './parseCertificate';