mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Merge pull request #484 from srossross/error_handling
[merge] Added error handling example
This commit is contained in:
commit
94ec6fa5ce
26
examples/error-handling.js
Normal file
26
examples/error-handling.js
Normal file
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user