1

Calling a 'server-side' function in Google App Script can be achieved with:

google.script.run.withFailureHandler(CallbackFailure)
      .withSuccessHandler(CallbackSuccess).doSomething();

In Code.gs, how can I ensure CallbackFailure is called? I attempted:

function doSomething() {
   throw new Error( "Trigger CallbackFailure" );
}

However I receive an error because of an unhandled exception. I had hoped throwing an Error would call CallbackFailure - but it was just guess work and doesn't work.

1 Answer 1

1

I do not see any problem in your code, it should work fine.

I did in my index.html

google.script.run.withFailureHandler(function(e){console.log("failure handler",e)})
    .withSuccessHandler(function(e){console.log("success handler",e)}).doSomething();

and in my code.gs

function doSomething() {
   throw new Error( "Trigger CallbackFailure" );
}

and my browser console logged:

failure handler Error {name: "", message: "Error: Trigger CallbackFailure"}

withFailureHandler callback function is called if the server-side function throws an exception as stated in the documentation. This worked fine.

Maybe there could be some other issue in your script, you can share your container bound script if you like.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.