如何捕获UrlFetchApp.fetch异常 [英] How to catch UrlFetchApp.fetch exception

查看:184
本文介绍了如何捕获UrlFetchApp.fetch异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从 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

推荐答案

编辑:此参数为现在记录在这里

在返回非200状态代码时,可以使用未记录的高级选项muteHttpExceptions来禁用异常,然后检查响应的状态代码。有关此问题的更多信息和示例。

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆