Skip to content

Commit 6285038

Browse files
authored
fix(error handler): fix confusing error message (#509)
1 parent be99bc4 commit 6285038

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## next
44

5+
- fix(errorHandler): fix confusing error message ([#509](https://github.com/chimurai/http-proxy-middleware/pull/509))
56
- fix(proxy): close proxy when server closes ([#508](https://github.com/chimurai/http-proxy-middleware/pull/508))
67
- refactor(lodash): remove lodash ([#459](https://github.com/chimurai/http-proxy-middleware/pull/459)) ([#507](https://github.com/chimurai/http-proxy-middleware/pull/507)) ([TrySound](https://github.com/TrySound))
78
- fix(ETIMEDOUT): return 504 on ETIMEDOUT ([#480](https://github.com/chimurai/http-proxy-middleware/pull/480)) ([aremishevsky](https://github.com/aremishevsky))

src/handlers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type * as express from 'express';
12
import camelcase = require('camelcase');
23
import { getInstance } from './logger';
34
const logger = getInstance();
@@ -42,7 +43,7 @@ export function getHandlers(options) {
4243
return handlers;
4344
}
4445

45-
function defaultErrorHandler(err, req, res) {
46+
function defaultErrorHandler(err, req: express.Request, res: express.Response) {
4647
const host = req.headers && req.headers.host;
4748
const code = err.code;
4849

@@ -63,7 +64,7 @@ function defaultErrorHandler(err, req, res) {
6364
}
6465
}
6566

66-
res.end('Error occured while trying to proxy to: ' + host + req.url);
67+
res.end(`Error occured while trying to proxy: ${host}${req.url}`);
6768
}
6869

6970
function logClose(req, socket, head) {

test/unit/handlers.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe('default proxy error handler', () => {
119119

120120
it('should end the response and return error message', () => {
121121
proxyError(mockError, mockReq, mockRes, proxyOptions);
122-
expect(errorMessage).toBe('Error occured while trying to proxy to: localhost:3000/api');
122+
expect(errorMessage).toBe('Error occured while trying to proxy: localhost:3000/api');
123123
});
124124

125125
it('should not set the http status code to: 500 if headers have already been sent', () => {
@@ -131,6 +131,6 @@ describe('default proxy error handler', () => {
131131
it('should end the response and return error message', () => {
132132
mockRes.headersSent = true;
133133
proxyError(mockError, mockReq, mockRes, proxyOptions);
134-
expect(errorMessage).toBe('Error occured while trying to proxy to: localhost:3000/api');
134+
expect(errorMessage).toBe('Error occured while trying to proxy: localhost:3000/api');
135135
});
136136
});

0 commit comments

Comments
 (0)