Skip to content

Commit 32a4088

Browse files
committed
DOC: Added error handling example
1 parent 5dcdf2b commit 32a4088

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

examples/error-handling.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var caronte = require('../index');
2+
/*
3+
* Create your proxy server
4+
*/
5+
var proxyServer = caronte.createProxyServer({target:'http://localhost:30404', ws:true});
6+
7+
// Register an error handler for web requests
8+
proxyServer.ee.on("caronte:outgoing:web:error", function(err, req, res){
9+
res.writeHead(502);
10+
res.end("There was an error proxying your request");
11+
});
12+
13+
// Register an error handler for web-socket requests
14+
proxyServer.ee.on("caronte:outgoing:ws:error", function(err, req, socket, head){
15+
socket.close();
16+
});
17+
18+
// You may also use a wild card
19+
proxyServer.ee.on("*:*:*:error", function(err, req){
20+
console.log("The error event '" + this.event + "' happened errno: " + err.errno);
21+
});
22+
23+
24+
console.log("Proxy server is listening on port 8000");
25+
proxyServer.listen(8000);
26+

0 commit comments

Comments
 (0)