Reputation: 1719
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?
Upvotes: 0
Views: 4574
Reputation: 12673
Simply add the error parameter to your anonymous function.
google.script.run.withFailureHandler(function (error) {
showError(error, 'getMe');
}).getMe();
Upvotes: 2
Reputation: 45720
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")
}
...
Upvotes: 1