bbc / http-transport-cache

A HTTP spec compliant caching layer for http-transport.
Other
3 stars 5 forks source link

Timeouts if cache is unresponsive and staleIfError middleware is used #28

Closed eddyerburgh closed 5 years ago

eddyerburgh commented 5 years ago

Version

3.4.0

Steps to reproduce

What is expected?

Cache should timeout and return response

What is actually happening?

Cache times out and doesn't return response

Reproduction


async function example() {

  class mockCatbox {
    isReady() {
      return true;
    }

    get() {
      return new Promise(() => {});
    }

    set() {
      return new Promise(() => {
        // setTimeout to keep node process running
        setTimeout(() => {}, 60000)
      });
    }
  }

  const cache = require('@bbc/http-transport-cache');
  const HttpTransport = require('@bbc/http-transport');

  const mcb = new mockCatbox();

  const url = 'https://ibl.api.bbc.co.uk/ibl/v1/episodes/p0740k63?rights=web&availability=available&mixin=live';

  const client = HttpTransport.createBuilder()
        .use(cache.maxAge(mcb, {timeout: 2000, ignoreCacheErrors: true}))
        .use(cache.staleIfError(mcb))
        .createClient();

  const body = await client.get(url)
    .asBody();

  console.log(body);
}

example();