Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(error handler): re-throw http-proxy missing target error #517

Merged
merged 1 commit into from
Apr 6, 2021
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
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);
});
});