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