Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## next

- fix(errorHandler): fix confusing error message ([#509](https://github.com/chimurai/http-proxy-middleware/pull/509))
- fix(proxy): close proxy when server closes ([#508](https://github.com/chimurai/http-proxy-middleware/pull/508))
- 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))
- fix(ETIMEDOUT): return 504 on ETIMEDOUT ([#480](https://github.com/chimurai/http-proxy-middleware/pull/480)) ([aremishevsky](https://github.com/aremishevsky))
Expand Down
5 changes: 3 additions & 2 deletions src/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as express from 'express';
import camelcase = require('camelcase');
import { getInstance } from './logger';
const logger = getInstance();
Expand Down Expand Up @@ -42,7 +43,7 @@ export function getHandlers(options) {
return handlers;
}

function defaultErrorHandler(err, req, res) {
function defaultErrorHandler(err, req: express.Request, res: express.Response) {
const host = req.headers && req.headers.host;
const code = err.code;

Expand All @@ -63,7 +64,7 @@ function defaultErrorHandler(err, req, res) {
}
}

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

function logClose(req, socket, head) {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/handlers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('default proxy error handler', () => {

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

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