Errors within an intercept are hard to find
Opened this issue · 0 comments
sholladay commented
Using this proxy, the contents of http://example.com
will show up in your browser, instead of http://tired.com
.
'use strict';
process.on('unhandledRejection', (err) => {
throw err;
});
const proxy = require('hoxy').createServer({
reverse : 'http://www.example.com/'
});
proxy.on('error warn info debug', (event) => {
console.error('event:', event);
});
proxy.intercept('request', (outRequest, outResponse) => {
someundeclaredvariable;
outRequest.fullUrl('http://tired.com');
});
proxy.listen(8001, () => {
const addr = proxy.address();
console.log(`Listening on: ${addr.address}:${addr.port}`);
});
While the client should really be getting a 500 response, a much more pressing concern is the lack of any kind of log or stack trace that even hints there was a problem. Undeclared variables can be noticed by IDEs, but in my real world case I had accidentally triggered a code path that lead to a throw new Error()
, which took a while to track down. IMO if the server wants to stay up, it needs to tell people what happened. Otherwise it needs to crash. Doing neither is alarming.