⭐️ bestfetch

CacheMissError

An Error that represents a cache miss.

import { CacheMissError } from 'bestfetch';

One of the options that you can pass to bestfetch is cachePolicy. If you specify your policy to be "cache-only" and no response exists in the cache, then the Promise will reject.

The error that is passed to the .catch() callback will be an instance of CacheMissError.

Example Usage

You can use the CacheMissError to determine if a cache miss is the cause of the Promise's rejection.

💁‍♀️ Heads up! You can copy and paste the following code snippet into your browser's developer tools to try it out!
bestfetch('https://jsonplaceholder.typicode.com/todos/1', {
  cachePolicy: 'cache-only'
})
  .catch(err => {
    if (err instanceof CacheMissError) {
      console.log('This request did not have a response in the cache.');
    }
  });