greim / hoxy

Web-hacking proxy API for node
http://greim.github.io/hoxy/
MIT License
599 stars 97 forks source link

Errors within an intercept are hard to find #80

Open sholladay opened 8 years ago

sholladay commented 8 years ago

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.