Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const API_URL = '...';
- const TIMEOUT = 10; // seconds
- export default (path) => {
- /* global fetch */
- const req = fetch(API_URL + path);
- const timeout = new Promise((resolve, reject) => {
- return setTimeout(() => reject(new Error('request timeout')), TIMEOUT * 1000);
- });
- return Promise.race([req, timeout]).then(response => response.json());
- };
Add Comment
Please, Sign In to add comment