UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

39 lines (36 loc) 1.3 kB
// tslint:disable:no-console // import * as moment from 'moment'; const TIMEOUT_MS = 5000; const INTERVAL_MS = 3000; let i = 0; setInterval( async () => { i += 1; try { const url = String(process.env.DISCONTINUE_PEOPLE_URL); const res = await fetch( url, { signal: AbortSignal.timeout(TIMEOUT_MS), method: 'GET' } ); const result = await res.text(); console.log('result', result, i); console.log('res.status', res.status, i); } catch (err) { console.error(err); if (err.name === 'TimeoutError') { console.error('Timeout: It took more than 5 seconds to get the result!'); } else if (err.name === 'AbortError') { console.error('Fetch aborted by user action (browser stop button, closing tab, etc.'); } else if (err.name === 'TypeError') { console.error('AbortSignal.timeout() method is not supported'); } else { // A network error, or some other problem. console.error(`Error: type: ${err.name}, message: ${err.message}`); } } }, INTERVAL_MS );