catch语句中的promise被拒绝后继续:Node.JS



预期行为:

catch块将错误打印到控制台后,代码将继续

行为:

代码退出程序。

尝试的方法:

我试着用回车;声明:那没有任何作用。我还尝试使用continue;语句,该语句出错。我还试着把整件事都包在一个试玩包里,结果也出现了同样的行为。

代码:

function readProxies() {
const rl = readline.createInterface({
input: fs.createReadStream(debug.proxy_file),
output: process.stdout,
terminal: false
});
rl.on('line', (line) => {
var ipPattern = new RegExp(/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/g);
var justIp = ipPattern.exec(line);
var oneProxy = ip2proxy.getAll(justIp[0])
if (oneProxy.Is_Proxy == 0) {
console.log('worked')
fetch('https://returning-json.workers-sites-examples.workers.dev/', {
agent: new ProxyAgent(debug.protocol + '://' + line, {
tunnel: true, // If true, will tunnel all HTTPS using CONNECT method
timeout: 2000, // Time in milli-seconds, to maximum wait for proxy connection to establish
})
})
.then(res => res.text())
.then(body => console.log(body))
.catch(err => {
console.log(err)
})
} else {
console.log('not worked')
}
});
rl.on('close', () => {
console.log('closed')
});
}

编辑:derpirscher,谢谢!

";闭合的";打印到控制台中让我了解了一下发生了什么。事实证明,一切都很顺利,我只需要在catch语句中放入一个return;,然后用更多的代理填充debug.proxy_file。他们中只有一人通过了第一次检查,所以只有一人接受了测试是有道理的。谢谢你的帮助!

最新更新