Error handling withFailureHandler的自定义故障处理程序-谷歌应用程序脚本

Error handling withFailureHandler的自定义故障处理程序-谷歌应用程序脚本,error-handling,google-apps-script,Error Handling,Google Apps Script,我正在尝试获取有关google.script.run失败时的更多信息。我知道我可以得到一个基本的错误处理回调函数,用如下方式向我提供错误消息: google.script.run.withFailureHandler(handleError).getMe(); ... if (errDetected) { throw new error("Custom message") } ... 其中handleError获取为错误消息传入的参数 function handleError(error

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

google.script.run.withFailureHandler(handleError).getMe();
...
if (errDetected) {
  throw new error("Custom message")
}
...
其中
handleError
获取为错误消息传入的参数

function handleError(error) {
  console.log(error);
}
但是,如果我想创建一个自定义错误处理程序来提供引发异常的位置,我可以在
withFailureHandler
上使用自定义函数,如下所示:

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

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

错误处理程序从服务器上引发的异常接收错误事件。要传递自定义消息,请让服务器端代码执行以下操作:

google.script.run.withFailureHandler(handleError).getMe();
...
if (errDetected) {
  throw new error("Custom message")
}
...

只需将error参数添加到匿名函数中即可

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