如何捕获 UrlFetchApp.fetch 异常 [英] How to catch UrlFetchApp.fetch exception
问题描述
有什么办法可以从 UrlFetchApp.fetch
中捕获异常?
Is there any way to catch the exception from UrlFetchApp.fetch
?
我想我可以使用 response.getResponseCode()
来检查响应代码,但我不能,例如,当出现 404 错误时,脚本不会继续并停止在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
推荐答案
Edit:这个参数现在是 此处记录.
您可以使用未公开的高级选项muteHttpExceptions"在返回非 200 状态代码时禁用异常,然后检查响应的状态代码.有关此问题的更多信息和示例.
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.
这篇关于如何捕获 UrlFetchApp.fetch 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!