From e2043455090493d3fface37ba4d69a8d11b15553 Mon Sep 17 00:00:00 2001 From: chimurai <655241+chimurai@users.noreply.github.com> Date: Sun, 18 Apr 2021 15:03:59 +0200 Subject: [PATCH] fix(log error): handle undefined target when websocket errors (#527) --- CHANGELOG.md | 3 ++- src/http-proxy-middleware.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f71d4ed4..1c53e02a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## next -- feat(handler): response interceptor +- feat(handler): response interceptor ([#520](https://github.com/chimurai/http-proxy-middleware/pull/520)) +- fix(log error): handle undefined target when websocket errors ([#527](https://github.com/chimurai/http-proxy-middleware/pull/527)) ## [v1.1.2](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.1.2) diff --git a/src/http-proxy-middleware.ts b/src/http-proxy-middleware.ts index fe13c3bf..b93ae92f 100644 --- a/src/http-proxy-middleware.ts +++ b/src/http-proxy-middleware.ts @@ -183,10 +183,10 @@ export class HttpProxyMiddleware { } }; - private logError = (err, req: Request, res: Response, target) => { + private logError = (err, req: Request, res: Response, target?) => { const hostname = req.headers?.host || req.hostname || req.host; // (websocket) || (node0.10 || node 4/5) const requestHref = `${hostname}${req.url}`; - const targetHref = `${target.href}`; + const targetHref = `${target?.href}`; // target is undefined when websocket errors const errorMessage = '[HPM] Error occurred while proxying request %s to %s [%s] (%s)'; const errReference = 'https://nodejs.org/api/errors.html#errors_common_system_errors'; // link to Node Common Systems Errors page