daily pastebin goal
83%
SHARE
TWEET

Untitled

a guest Mar 14th, 2018 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const API_URL = '...';
  2. const TIMEOUT = 10; // seconds
  3.  
  4. export default (path) => {
  5.   /* global fetch */
  6.   const req = fetch(API_URL + path);
  7.  
  8.   const timeout = new Promise((resolve, reject) => {
  9.     return setTimeout(() => reject(new Error('request timeout')), TIMEOUT * 1000);
  10.   });
  11.  
  12.   return Promise.race([req, timeout]).then(response => response.json());
  13. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top