Skip to content

Commit

Permalink
fix(error handler): re-throw http-proxy missing target error (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
chimurai authored Apr 6, 2021
1 parent 40e8763 commit 030ea2e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 7 additions & 0 deletions test/unit/handlers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 030ea2e

Please sign in to comment.