express-http-proxyerror handling

我使用node,express和express-http-proxybuild立了一个本地代理服务器,它将请求redirect到只能通过VPN使用的远程后端。 这在VPN连接build立时运行良好。 但是,当没有VPN连接,我得到这个错误:


     _http_outgoing.js:346
        抛出新的错误('发送后不能设置标题')。
         ^

    错误:发送后无法设置标题。
        在ServerResponse.OutgoingMessage.setHeader(_http_outgoing.js:346:11)
        在/path/to/my/project/proxy/node_modules/express/lib/application.js:152:9
         (/path/to/my/project/proxy/node_modules/express/lib/router/index.js:150:14)
        在SendStream.error(/path/to/my/project/proxy/node_modules/serve-static/index.js:74:37)
        在emitOne(events.js:77:13)
        在SendStream.emit(events.js:169:7)
        在SendStream.error(/path/to/my/project/proxy/node_modules/serve-static/node_modules/send/lib/send.js:147:51)
        在SendStream.onStatError(/path/to/my/project/proxy/node_modules/serve-static/node_modules/send/lib/send.js:248:48)
         at /path/to/my/project/proxy/node_modules/serve-static/node_modules/send/lib/send.js:320:26
        在FSReqWrap.oncomplete(fs.js:82:15)

我的代理设置是:


     app.use('/ the / api',proxy('the.domain.behind.vpn:8026',{
        超时:4000,

         forwardPath:function(req,res){
            的console.log(nodeUrl.parse(req.url)。path);

             return“/ the / api”+ nodeUrl.parse(req.url).path;
         },

         intercept:function(rsp,data,req,res,callback){
             data = data.toString(“utf8”)。replace(/ http \:\ / \ \ \ .domain \ .behind \ .vpn \:8026 / g,“http:// localhost:61000”);
            callback(null,data);
         },

         decorateRequest:function(proxyReq,originalReq){
             if(proxyReq.method ===“HEAD”){
                 proxyReq.method =“GET”;
             }

            返回proxyReq;
         }
     }));

是什么原因导致这个错误,我怎么能抓住它呢?