From 32a40889cedfd6b0d92224aa921700a7b7271c68 Mon Sep 17 00:00:00 2001 From: srossross Date: Sat, 21 Sep 2013 13:15:34 -0700 Subject: [PATCH] DOC: Added error handling example --- examples/error-handling.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/error-handling.js diff --git a/examples/error-handling.js b/examples/error-handling.js new file mode 100644 index 0000000..06b126e --- /dev/null +++ b/examples/error-handling.js @@ -0,0 +1,26 @@ +var caronte = require('../index'); +/* + * Create your proxy server + */ +var proxyServer = caronte.createProxyServer({target:'http://localhost:30404', ws:true}); + +// Register an error handler for web requests +proxyServer.ee.on("caronte:outgoing:web:error", function(err, req, res){ + res.writeHead(502); + res.end("There was an error proxying your request"); +}); + +// Register an error handler for web-socket requests +proxyServer.ee.on("caronte:outgoing:ws:error", function(err, req, socket, head){ + socket.close(); +}); + +// You may also use a wild card +proxyServer.ee.on("*:*:*:error", function(err, req){ + console.log("The error event '" + this.event + "' happened errno: " + err.errno); +}); + + +console.log("Proxy server is listening on port 8000"); +proxyServer.listen(8000); +