Skip to content

Commit

Permalink
Add expBackOffFetch(): helper function to automatically handles expon…
Browse files Browse the repository at this point in the history
…ential backoff on UrlFetch use
  • Loading branch information
JeanRemiDelteil committed Mar 30, 2018
1 parent 182272f commit cb4a995
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/ErrorHandler.gs.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ function expBackoff(func) {
}
}

/**
* Helper function to automatically handles exponential backoff on UrlFetch use
*
* @param {string} url
* @param {Object} params
*
* @return {UrlFetchApp.HTTPResponse} - fetch response
*/
function expBackOffFetch(url, params) {
params = params || {};

params.muteHttpExceptions = true;

return ErrorHandler.expBackoff(function(){
return UrlFetchApp.fetch(url, params);
});
}

/**
* If we simply log the error object, only the error message will be submitted to Stackdriver Logging
* Best to re-write the error as a new object to get lineNumber & stack trace
Expand Down Expand Up @@ -163,6 +181,7 @@ function logError(e, additionalParams) {
this['ErrorHandler'] = {
// Add local alias to run the library as normal code
expBackoff: expBackoff,
expBackOffFetch: expBackOffFetch,
logError: logError
};

Expand Down

0 comments on commit cb4a995

Please sign in to comment.