包详细信息

stentor-service-fetch

michaelmyers1.5kApache-2.01.60.55

Simple fetch service with timeouts

自述文件

stentor-service-fetch

A simple service meant to be extended to give you a protected this.fetch() method with a timeout.

Timeouts are crucial when designing for conversations, they allow you to communicate back to the user that certain requests are taking longer than expected.

import { FetchService, TimeoutError } from "../FetchService";

class TestService extends FetchService {
  public getWeatherAlerts(state: string): Promise<any> {
    const url = `https://api.weather.gov/alerts/active?area=${state}`;

    return this.fetch(url).then((response) => {
      return response.json();
    });
  }
}