使用FailureHandler的自定义失败处理程序 - Google Apps脚本 [英] Custom Failure Handler for withFailureHandler - Google Apps Script

查看:523
本文介绍了使用FailureHandler的自定义失败处理程序 - Google Apps脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获取更多的信息,当 google.script.run 失败时。我知道我可以得到一个基本的错误处理回调函数给我这样的错误消息:

I'm trying to get more information for when google.script.run fails. I know that I can get a basic error handling callback function to give me the error message with something like this:

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

其中 handleError 获取传入的参数错误消息。

Where handleError gets an argument passed in for the error message.

function handleError(error) {
  console.log(error);
}

但是,如果我想创建一个自定义错误处理程序,在异常被抛出的情况下,我可以使用 withFailureHandler 中的自定义函数,如下所示:

However, if I wanted to created a custom error handler that provided the location of where the exception was being thrown, I could use a custom function on withFailureHandler, like this:

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

使用这种方法我遇到一个问题。如何捕获错误消息传递给我的 showError()错误处理程序?

With this method I'm stumped with one issue. How do I capture the error message to pass to my showError() error handler?

推荐答案

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

Simply add the error parameter to your anonymous function.

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

这篇关于使用FailureHandler的自定义失败处理程序 - Google Apps脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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