[slightlyoff/ServiceWorker] caches.match() rejection on missing name is a footgun (#891)

Currently we offer `caches.match()` as a shorthand for looking for a request in all the Cache objects.  An optional name can be passed to look in a specific Cache object.  Currently, if that named Cache does not exist we reject `caches.match()`.

I've seen this trip up a few people now.  It seems most people expect `caches.match(url, { name: 'foo' })` to be a shorthand for:

```
caches.open('foo').then(function(cache) {
  return cache.match(url);
});
```

But what we actually implement is:

```
caches.has('foo').then(function(result) {
  if (result) {
    return Promise.reject(NotFoundErr);
  }
  return cache.open('foo');
}).then(function(cache) {
  return cache.match(url);
});
```

Since `cache.match()` does not normally reject its very surprising to people that `caches.match()` can reject.  Its also the kind of thing that can work in many cases, but then start rejecting when your CacheStorage state changes.

I'd like to propose we just resolve `undefined` if the named cache is not present.

---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/891

Received on Wednesday, 4 May 2016 16:12:03 UTC