diff --git a/src/handlers.ts b/src/handlers.ts index 7e2b0e3f..e44e5dc7 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -54,6 +54,11 @@ export function getHandlers(options: Options) { } function defaultErrorHandler(err, req: express.Request, res: express.Response) { + // Re-throw error. Not recoverable since req & res are empty. + if (!req && !res) { + throw err; // "Error: Must provide a proper URL as target" + } + const host = req.headers && req.headers.host; const code = err.code; diff --git a/test/unit/handlers.spec.ts b/test/unit/handlers.spec.ts index 792b7333..55789270 100644 --- a/test/unit/handlers.spec.ts +++ b/test/unit/handlers.spec.ts @@ -133,4 +133,11 @@ describe('default proxy error handler', () => { proxyError(mockError, mockReq, mockRes, proxyOptions); expect(errorMessage).toBe('Error occured while trying to proxy: localhost:3000/api'); }); + + it('should re-throw error from http-proxy when target is missing', () => { + mockRes.headersSent = true; + const error = new Error('Must provide a proper URL as target'); + const fn = () => proxyError(error, undefined, undefined, proxyOptions); + expect(fn).toThrowError(error); + }); });