@@ -51,10 +51,18 @@ const getCANotAfter = (notBefore: any) => {
51
51
// Function to check if a certificate file has expired
52
52
export const isCertificateExpired = async ( certFilePath : string ) : Promise < boolean > => {
53
53
return new Promise ( ( resolve , reject ) => {
54
+
54
55
try {
56
+ // Check if the file exists
57
+ if ( ! fs . existsSync ( certFilePath ) ) {
58
+ reject ( 'Certificate not found' )
59
+ }
60
+
55
61
// Read the certificate file
56
62
const certData = fs . readFileSync ( certFilePath , 'utf8' )
57
63
64
+
65
+
58
66
// check if cert exists
59
67
if ( ! certData ) {
60
68
reject ( 'Certificate not found' )
@@ -69,10 +77,11 @@ export const isCertificateExpired = async (certFilePath: string): Promise<boolea
69
77
const isExpired = expiryDate < new Date ( )
70
78
71
79
resolve ( isExpired )
80
+
72
81
} catch ( error ) {
73
82
// Handle errors
74
83
console . error ( `Error checking certificate expiry: ${ error } ` )
75
- reject ( error ) // Reject the promise with the error
84
+ // reject(error) // Reject the promise with the error
76
85
}
77
86
} )
78
87
}
@@ -82,6 +91,12 @@ export const isDomainExists = async (domainToCheck: string, certificatePath: str
82
91
// Read the certificate file
83
92
const certificateContents = fs . readFileSync ( certificatePath , 'utf8' )
84
93
94
+
95
+ if ( ! certificateContents ) {
96
+
97
+ throw new Error ( 'Certificate not found' )
98
+ }
99
+
85
100
// Parse the certificate data
86
101
const certificate = forge . pki . certificateFromPem ( certificateContents )
87
102
0 commit comments