Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch UrlFetchApp.fetch exception

Tags:

Is there any way to catch the exception from UrlFetchApp.fetch?

I thought I can use response.getResponseCode() to check the response code, but I'm not able to, for e.g when there is 404 error, the script not continue and just stop at UrlFetchApp.fetch

like image 872
louis Avatar asked Jul 30 '12 09:07

louis


People also ask

Is UrlFetchApp fetch async?

fetch() will always be sync, no matter whether you declare your function as async or not, due to the GAS-API-design.

What is a URL fetch call?

URL Fetch. This service allows scripts to access other resources on the web by fetching URLs. A script can use the UrlFetch service to issue HTTP and HTTPS requests and receive responses. The UrlFetch service uses Google's network infrastructure for efficiency and scaling purposes.

What is UrlFetchApp fetch()?

UrlFetchApp. Fetch resources and communicate with other hosts over the Internet. This service allows scripts to communicate with other applications or access other resources on the web by fetching URLs. A script can use the URL Fetch service to issue HTTP and HTTPS requests and receive responses.


1 Answers

Edit: This parameter is now documented here.

You can use the undocumented advanced option "muteHttpExceptions" to disable exceptions when a non-200 status code is returned, and then inspect the status code of the response. More information and an example is available on this issue.

like image 82
Eric Koleda Avatar answered Sep 20 '22 21:09

Eric Koleda