fix: proxy service now catches handler exceptions properly

This commit is contained in:
Ben Allfree 2023-01-24 16:21:20 +00:00
parent 91ef1f928e
commit e3bd7a17d5

View File

@ -22,7 +22,7 @@ export type ProxyMiddleware = (
proxy: Server proxy: Server
host: string host: string
} }
) => void ) => void | Promise<void>
export type ProxyServiceConfig = { export type ProxyServiceConfig = {
coreInternalUrl: string coreInternalUrl: string
@ -56,8 +56,8 @@ export const proxyService = mkSingleton(async (config: ProxyServiceConfig) => {
await m(req, res) await m(req, res)
} }
} catch (e) { } catch (e) {
const msg = `${e}` const msg = (() => (e instanceof Error ? e.message : `${e}`))()
error(msg) warn(msg)
res.writeHead(403, { res.writeHead(403, {
'Content-Type': `text/plain`, 'Content-Type': `text/plain`,
}) })
@ -133,7 +133,7 @@ export const proxyService = mkSingleton(async (config: ProxyServiceConfig) => {
return return
} }
dbg(`${url} matches ${urlFilters}, sending to handler`) dbg(`${url} matches ${urlFilters}, sending to handler`)
handler(req, res, { host, subdomain, coreInternalUrl, proxy }) return handler(req, res, { host, subdomain, coreInternalUrl, proxy })
}) })
} }