Search code examples
google-app-maker

App maker override server side error message


I have a problem with the server-side error management on Google App Maker.

Here an exemple of my code

Server-side

function serverSideFn() {
    // Consider the error to be throw.

    if ( anError ) {
        throw new Error("A specific error message");
    }

}

Client-side

function clientSideFn() {
    google.script.run
        .withSuccessHandler(function(result) {
            // Success code...
        })
        .withFailureHandler(function(error) {
            console.log(error.message); // The message error here is not the same if I have or not the Admin role.
            showErrorPopup(error.message);
        })
        .serverSideFn();
}

When I execute the "clientSideFn" function with default role Admin, I have the good message ("A specific error message"), but if I don't have the Admin role, I have a "Server Error" message instead of the expected.

I've tried to use the developer account option, and set Admin role to this account and execute the server side scripts, but the error is still present for users without Admin role.

I've also tried to throw a custom Exception, but the error is still changed on client side.

What I can change to got the expected message when the user don't have the Admin role ?


Solution

  • The relevant documentation to your question is located here https://developers.google.com/appmaker/scripting/api/server. The basics is that you use:

    throw new app.ManagedError('Your custom message here');