From 3f48d50de1393ca94c6c49cac5f74471979a5099 Mon Sep 17 00:00:00 2001 From: chimurai <655241+chimurai@users.noreply.github.com> Date: Wed, 20 Apr 2022 21:42:03 +0200 Subject: [PATCH] fix(proxyReqWs): catch socket errors --- src/_handlers.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/_handlers.ts b/src/_handlers.ts index 9d3be970..3737aa01 100644 --- a/src/_handlers.ts +++ b/src/_handlers.ts @@ -11,8 +11,16 @@ export function init(proxy: httpProxy, option: Options): void { proxy.on(eventName, handlers[eventName]); } - proxy.on('econnreset', (err, req, res, target) => { - logger.error(`[HPM] ECONNRESET: %s`, err); + // https://github.com/webpack/webpack-dev-server/issues/1642 + proxy.on('econnreset', (error, req, res, target) => { + logger.error(`[HPM] ECONNRESET: %O`, error); + }); + + // https://github.com/webpack/webpack-dev-server/issues/1642#issuecomment-1104325120 + proxy.on('proxyReqWs', (proxyReq, req, socket, options, head) => { + socket.on('error', (error) => { + logger.error(`[HPM] WebSocket error: %O`, error); + }); }); logger.debug('[HPM] Subscribed to http-proxy events:', Object.keys(handlers));