mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-04 21:19:53 +08:00
17 lines
441 B
TypeScript
17 lines
441 B
TypeScript
import pRetry = require('p-retry');
|
|
import fetch from 'node-fetch';
|
|
|
|
const run = () => fetch('https://sindresorhus.com/unicorn')
|
|
.then(response => {
|
|
// abort retrying if the resource doesn't exist
|
|
if (response.status === 404) {
|
|
throw new pRetry.AbortError(response.statusText);
|
|
}
|
|
|
|
return response.text();
|
|
});
|
|
|
|
pRetry(run, {retries: 5}).then(result => {
|
|
const str: string = result;
|
|
});
|