Custom Failure Handler for withFailureHandler - Go

2019-06-09 13:25发布

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();

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

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

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();

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

2条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-06-09 14:19

Simply add the error parameter to your anonymous function.

google.script.run.withFailureHandler(function (error) {
  showError(error, 'getMe'); 
}).getMe();
查看更多
疯言疯语
3楼-- · 2019-06-09 14:20

An errorHandler receives the error event from an exception that's thrown on the server. To pass a custom message, have your server side code do something like this:

...
if (errDetected) {
  throw new error("Custom message")
}
...
查看更多
登录 后发表回答