How to catch UrlFetchApp.fetch exception

louis picture louis · Jul 30, 2012 · Viewed 30.4k times · Source

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

Answer

Eric Koleda picture Eric Koleda · Jul 30, 2012

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.