Error catching for invalid certificates
parent
6390276306
commit
91c7b0c6f5
|
@ -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';
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Reference in New Issue