Skip to content

Commit 030ea2e

Browse files
authored
fix(error handler): re-throw http-proxy missing target error (#517)
1 parent 40e8763 commit 030ea2e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/handlers.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ export function getHandlers(options: Options) {
5454
}
5555

5656
function defaultErrorHandler(err, req: express.Request, res: express.Response) {
57+
// Re-throw error. Not recoverable since req & res are empty.
58+
if (!req && !res) {
59+
throw err; // "Error: Must provide a proper URL as target"
60+
}
61+
5762
const host = req.headers && req.headers.host;
5863
const code = err.code;
5964

test/unit/handlers.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,11 @@ describe('default proxy error handler', () => {
133133
proxyError(mockError, mockReq, mockRes, proxyOptions);
134134
expect(errorMessage).toBe('Error occured while trying to proxy: localhost:3000/api');
135135
});
136+
137+
it('should re-throw error from http-proxy when target is missing', () => {
138+
mockRes.headersSent = true;
139+
const error = new Error('Must provide a proper URL as target');
140+
const fn = () => proxyError(error, undefined, undefined, proxyOptions);
141+
expect(fn).toThrowError(error);
142+
});
136143
});

0 commit comments

Comments
 (0)