自从将Firebase的Cloud Functions升级到Node8和ES17以来,尝试更新功能时出现TsLint错误。它为这段代码抛出Promises must be handled appropriately
:
app.get('*', (req, res) => {
const isBot = detectBot(req.headers['user-agent']);
if (isBot) {
const botUrl = generateUrl(req);
// If bot, fetch url via rendertron
fetch(`https://foo.com/render/${botUrl}`)
.then(rendertronRes => rendertronRes.text())
.then(body => {
res.set('Cache-Control', 'public, max-age=300, s-maxage=600');
res.set('Vary', 'User-Agent');
res.send(body.toString());
});
} else {
// Not a bot, fetch the regular Angular app
fetch('https://bar.com/')
.then(regularRes => regularRes.text())
.then(body => {
res.send(body.toString());
})
.catch(err => res.send(err));
}
});
最奇怪的部分是它抱怨第二次获取,而不是第一次获取。
答案 0 :(得分:4)
尝试为每个然后
编写 catch 块