Search code examples
javascriptgoogle-apps-scriptrequestfetchurlfetch

How to catch error from UrlFetchApp.fetchAll?


UrlFetchApp.fetchAll speeds up the execution time. But with many requests, often occurs errors (429, 500, 503). In most cases, a second request will solve it. How can I catch them? According benchmark, HTTPResponse[] has a different order than request array. Thus I can't send new request (UrlFetchApp.fetch), don't know url and params.

let requests = [
    { url: '', muteHttpExceptions: true }, 
    { url: '', muteHttpExceptions: true }
];
let responses = UrlFetchApp.fetchAll(requests);

Solution

  • According benchmark, HTTPResponse[] has a different order than request array.

    Im wrong. Summary section gave the next rule:

    After it worked by the asynchronous processing, the returned values is reordered by the order of requests.

    In practice my case, it is true.

    Thanks Tanaike