如何处理网络错误,使它们不会出现在 chrome 开发者控制台中?

How do I handle network errors so they don't appear in chrome developer console?

我在服务工作者中有一些代码 运行ning 可以刷新当前缓存的资源:

const RESOURCE_CACHE = 'resources-v1';
caches.open(RESOURCE_CACHE).then(function addUrlsToCache(cache) {
    return cache.addAll([
        '/resources/style.css',
        '/resources/fonts/led',
        '/resources/script.js',
        '/img/roundel-tube.png',
        '/img/roundel-dlr.png',
        '/img/roundel-overground.png',
    ]);
}).catch(function (error) {
    console.error("Failed to cache resources:", error.message);
})

为了测试错误处理,我再次禁用了开发服务器和 运行 这个客户端代码。在这种情况下,我希望看到一条错误消息:Failed to cache resources: Failed to fetch。但我实际上看到了这一段代码的 7 条错误消息:

这让我感到困惑,因为我认为我在这里使用 promises 的方式会处理其他 6 个,因此它们永远不会冒泡到控制台。我需要做哪些不同的事情,以便控制台永远不会显示我在代码中处理的网络错误?

如果您主要担心的是:

It's just really hard to debug things when the console is full bogus error messages which I'm trying to handle

那么您可以使用 console.clear() (reference)

Working Demo in JsFiddle

点击来自 a bug @wOxOm posted, I came across a helpful comment 的链接:

In Chrome you can click the Filter icon then "Hide network messages".

虽然它比我想要的要重一些(因为它适用于当前页面上的所有网络流量),但它似乎是实现我在当前版本中寻找的目标的最佳方式共 Chrome.