@samitouri / QOSami-HFS / commits / f43e99e7

fix: admin/internet: better error messages making certificate

Massimo Melina committed Mar 19, 2024 at 10:36 UTC f43e99e73e8d1e3ccbbe2fea294695fd520c20f7
2 files changed +19 -3
src/acme.ts
+16 -2
@@ -1,4 +1,15 @@
1 -import { DAY, Dict, haveTimeout, HOUR, HTTP_BAD_REQUEST, HTTP_FAILED_DEPENDENCY, HTTP_OK, MINUTE, repeat } from './cross'
1 +import {
2 + DAY,
3 + Dict,
4 + haveTimeout,
5 + HOUR,
6 + HTTP_BAD_REQUEST,
7 + HTTP_FAILED_DEPENDENCY,
8 + HTTP_OK,
9 + HTTP_SERVER_ERROR,
10 + MINUTE,
11 + repeat
12 +} from './cross'
13 import { createServer, RequestListener } from 'http'
14 import { Middleware } from 'koa'
15 import { getNatInfo, upnpClient } from './nat'
@@ -95,7 +106,10 @@ async function generateSSLCert(domain: string, email?: string, altNames?: string
106
107 export const makeCert = debounceAsync(async (domain: string, email?: string, altNames?: string[]) => {
108 if (!domain) return new ApiError(HTTP_BAD_REQUEST, 'bad params')
98 - const res = await generateSSLCert(domain, email, altNames)
109 + const res = await generateSSLCert(domain, email, altNames).catch(e => {
110 + throw !e.message?.includes('not match this challenge') ? e // another acme server?
111 + : Error("a different server is responding on port 80 of your domain(s)")
112 + })
113 const CERT_FILE = 'acme.cer'
114 const KEY_FILE = 'acme.key'
115 await fs.writeFile(CERT_FILE, res.cert)
src/api.net.ts
+3 -1
@@ -74,7 +74,9 @@ const apis: ApiHandlers = {
74 },
75
76 async make_cert({domain, email, altNames}) {
77 - await makeCert(domain, email, altNames)
77 + await makeCert(domain, email, altNames).catch(e => {
78 + throw new ApiError(HTTP_SERVER_ERROR, e.message || String(e))
79 + })
80 return {}
81 },
82