Skip to content

Commit 0d0f477

Browse files
authored
fix(dashmate): various ZeroSSL cert verification errors (#2339)
1 parent fa6e6bd commit 0d0f477

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

packages/dashmate/src/listr/tasks/ssl/zerossl/obtainZeroSSLCertificateTaskFactory.js

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,29 +173,54 @@ export default function obtainZeroSSLCertificateTaskFactory(
173173
skip: (ctx) => ctx.certificate && !['pending_validation', 'draft'].includes(ctx.certificate.status),
174174
task: async (ctx, task) => {
175175
let retry;
176+
let autoRetryCount = 0;
177+
const MAX_AUTO_RETRIES = 3; // Adjust based on requirements
176178
do {
177179
try {
178180
await verifyDomain(ctx.certificate.id, ctx.apiKey);
179181
} catch (e) {
180-
if (ctx.noRetry !== true) {
181-
retry = await task.prompt({
182-
type: 'toggle',
183-
header: chalk` An error occurred during verification: {red ${e.message}}
182+
// Error: The given certificate is not ready for domain verification
183+
// Sometimes this error means that certificate is already verified
184+
if (e.code === 2831) {
185+
const certificate = await getCertificate(ctx.apiKey, ctx.certificate.id);
186+
// Just proceed on certificate download if we see it's already issued.
187+
if (certificate.status === 'issued') {
188+
return;
189+
}
190+
}
191+
192+
if (e.type === 'domain_control_validation_failed') {
193+
// Retry on this undocumented error whatever it means
194+
if (autoRetryCount >= MAX_AUTO_RETRIES) {
195+
throw e;
196+
}
197+
autoRetryCount++;
198+
if (process.env.DEBUG) {
199+
// eslint-disable-next-line no-console
200+
console.warn(`Retry ${autoRetryCount}/${MAX_AUTO_RETRIES} verification due to domain_control_validation_failed error`);
201+
}
202+
await wait(5000);
203+
} else {
204+
if (ctx.noRetry !== true) {
205+
retry = await task.prompt({
206+
type: 'toggle',
207+
header: chalk` An error occurred during verification: {red ${e.message}}
184208
185209
Please ensure that port 80 on your public IP address ${ctx.externalIp} is open
186210
for incoming HTTP connections. You may need to configure your firewall to
187211
ensure this port is accessible from the public internet. If you are using
188212
Network Address Translation (NAT), please enable port forwarding for port 80
189213
and all Dash service ports listed above.`,
190-
message: 'Try again?',
191-
enabled: 'Yes',
192-
disabled: 'No',
193-
initial: true,
194-
});
195-
}
214+
message: 'Try again?',
215+
enabled: 'Yes',
216+
disabled: 'No',
217+
initial: true,
218+
});
219+
}
196220

197-
if (!retry) {
198-
throw e;
221+
if (!retry) {
222+
throw e;
223+
}
199224
}
200225
}
201226
} while (retry);

0 commit comments

Comments
 (0)