error-handling - withFailureHandler的自定义失败处理程序-Google Apps脚本

标签 error-handling google-apps-script

我正在尝试获取有关google.script.run失败时的更多信息。我知道我可以得到一个基本的错误处理回调函数,以类似以下方式为我提供错误消息:

google.script.run.withFailureHandler(handleError).getMe();

其中handleError获取为错误消息传递的参数。
function handleError(error) {
  console.log(error);
}

但是,如果我想创建一个自定义错误处理程序来提供抛出异常的位置,则可以在withFailureHandler上使用自定义函数,如下所示:
google.script.run.withFailureHandler(function () {
  showError(error, 'getMe'); 
}).getMe();

通过这种方法,我陷入了一个难题。如何捕获错误消息并传递给showError()错误处理程序?

最佳答案

只需将error参数添加到您的匿名函数中。

google.script.run.withFailureHandler(function (error) {
  showError(error, 'getMe'); 
}).getMe();

关于error-handling - withFailureHandler的自定义失败处理程序-Google Apps脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25066589/

相关文章:

python - TypeError : unsupported operand type(s) for -: 'list' and 'int'

swift - “ fatal error :在展开可选值时意外发现nil”是什么意思?

python - python解决方案中超过了时间限制

google-apps-script - Google应用程序脚本,gmail插件获取TextInput值

javascript - Google Sheets 应用程序脚本 HTML 页面隐藏关闭 (X) 按钮

google-apps-script - 我可以阻止具有编辑权限的人修改我的谷歌应用程序脚本吗?

r - R rmongodb try()未捕获可能由错误数据引起的错误

javascript - 为什么Webstorm显示不可能的结果?

google-apps-script - Google 电子表格脚本错误 : "Cannot convert (class) ... to Object[][]"

javascript - Google 脚本 - 调用 API - 错误对象