gapi auth2 fails with cb=gapi.loaded_0:43 Uncaught [object Object] exception if user denies permission to access google account data
<p>I am trying to make google plus login working for my website using gapi auth2 api.</p>

<p>The flow is like this:</p>

<p>User clicks on google+ button -> pop up to choose google account appears -> permission window (user allows/denies the permission to access account) -> I call my custom auth service using access_token provided by google -> login happens.</p>

<p>Everything else is working fine except for when user chooses the google account and then instead of allowing he clicks on 'Deny' button on permission window. In this case, I get the below exception:</p>

<p>I was expecting that when user denies the permission I will get a callback to my code from gapi but instead it fails.</p>

<p>Here is the code I wrote to do google+ login</p>

<pre><code>gapi.client.setApiKey(config.apiKey);
            var auth2 = gapi.auth2.getAuthInstance();
            if (auth2 == undefined) {
                auth2 = gapi.auth2.init({
                    client_id: config.clientId,
                    scope: config.scopes,
                    immediate: false
                });
            }
            auth2.then(function() {
                var options = new gapi.auth2.SigninOptionsBuilder();
                options.setScope(config.scopes); // Set scopes
                options.setPrompt('select_account consent'); // Get authorization from the user to access profile info
                var signIn = gapi.auth2.getAuthInstance().signIn(options);
                signIn.then(function() {
                    gapi.client.load('plus', 'v1', function() {
                        console.log("google plus api loaded.");
                        var request = gapi.client.plus.people.get({
                            'userId': 'me'
                        });
                        request.execute(function(resp) {
                            console.log(resp.displayName);
                        });
                    });
                    var authResult = gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse();
                    if (authResult &amp;&amp; !authResult.error) {
                        console.log("google auth success");
                        console.log(authResult.access_token);
                        var authService = new authServiceModel.authServiceResp({});
                        var formvalues = {};
                        formvalues.Method = 3;
                        formvalues.Source = 5;
                        formvalues.GoogleToken = authResult.access_token;
                        authService.fetch(formvalues);
                    } else {
                        if (authResult &amp;&amp; authResult.error) {
                            console.error('Unable to sign in:', authResult.error);
                        }
                        console.log("google auth failed");
                    }
                });
            });
</code></pre>

<p>Here are the screenshots:</p>

<p><a href="https://i.stack.imgur.com/qRGhv.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qRGhv.jpg" alt="enter image description here"></a></p>

<p>2.</p>

<p><a href="https://i.stack.imgur.com/I2FjC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I2FjC.jpg" alt="enter image description here"></a></p>

<p>3.</p>

<p><a href="https://i.stack.imgur.com/K6caN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K6caN.jpg" alt="enter image description here"></a></p>

<p>Click Deny.</p>

<p>Please look into the code and suggest what should I do to get a proper callback when 'Deny' button is clicked.</p>

<p>Thanks.</p>