@ghg/retry-urlfetchapp
v0.0.5
Published
Library that automatically retries URLFetchApp actions 3 times before eventually throwing an error
Downloads
7
Keywords
Readme
gas-retry-urlfetchapp
Introduction
This library provides a URLFetchApp wrapper that automatically retries up to three times whenever a request fails.
Installation
Install this library by adding 1VI7pJrakmggxc7nW5ENKDG7dTNB274yDp-NTzRVMQU58IH_wKJnDJxHz
to the library section of your Google Apps Script project.
Usage
This library inherits all functions of the original URLFetchApp class. For more help, please consult the original documentation.
// Destructure the methods you require
const { fetch, fetchAll, _retry } = RetryURLFetchApp;
// Fetch one url
fetch("https://jsonplaceholder.typicode.com/todos/1");
// Fetch with custom retry and timeout
fetch("https://jsonplaceholder.typicode.com/todos/1", {
attempts: 5,
timeout: 1000,
});
// Fetch multiple urls
fetchAll([
"https://jsonplaceholder.typicode.com/todos/1",
"https://jsonplaceholder.typicode.com/todos/2",
]);
// Fetch multiple with custom retry and timeout
fetchAll(
[
"https://jsonplaceholder.typicode.com/todos/1",
"https://jsonplaceholder.typicode.com/todos/2",
],
{ attempts: 5, timeout: 1000 }
);
// Retry any function
const attempts = 5;
const sleep = 1000;
function fn() {
throw new Error("Something went wrong...");
}
_retry(fn, 0, attempts, sleep);