Skip to content

Commit

Permalink
fix(log error): handle undefined target when websocket errors (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
chimurai authored Apr 18, 2021
1 parent 455ba47 commit e204345
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/http-proxy-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e204345

Please sign in to comment.