Returning rejected promise in popup button not close the popup

Using the login form in popup with 2 buttons,login and cancel as you guess and it works great if login service return resolved promise meaning login successful in my case.Popup close and return object from popup is what returned from login service.Its actually a access token from oauth service.Its great so far.
However,in case when failed login attempts,popup promise is resolved as rejected,popup keeps still on the screen but as its responseDeferred is resolved,there is no more action acceptable.
Im not sure how to deal with this using popup standarts usage.I tried either close method of popup and e.preventDefault but no success.

im pasting the actual code in my app

////Show standart popup
    showStdPopup: function (scope, title, template, successCallback, showCancelButton, okButtonText, cancelButtonText) {
        var self = this,
            CANCELLED = 'CANCELLED',
            defer = this.q.defer(),
            //Sadece title yeterli
            options = { title: title, scope: scope };
        //Html olmasi durumuna gore ilgili propa atama yapılıyor
        if (this.common.isHtml(template))
            options.templateUrl = template;
        else
            options.template = template;
        //Ok Buttonu
        options.buttons = [{
            text: '<b>' + (okButtonText || this.localization.get('Tamam')) + '</b>',
            type: 'button-positive',
            onTap: function (e) {
                return successCallback && successCallback(e);
            }
        }];
        //Cancel Butonu
        if (showCancelButton) {
            options.buttons.push({
                text: cancelButtonText || this.localization.get('Iptal'),
                onTap: function (e) {
                    return CANCELLED;
                }
            });
        }
        //Popup
        var popup = this.ionicPopup.show(options);
        scope.popup = popup;
        //Sonuc
        popup.then(function (data) {
            if (data === CANCELLED || data === undefined)
                defer.reject(CANCELLED);
            else
                defer.resolve(data);
        }, function (data) {
            defer.reject(data);
        });
        return defer.promise;
    },//Token servisine request cekip token bilgisini aliyoruz
    logIn: function (username, password) {
        var deferred = this.$q.defer();

       //Token path kontrol
        if (!this.securityConfig.oauthOptions.loginTokenPath) {
            throw new Error('Please define login token path');
        }
        //Token path
        var tokenPath = this.securityConfig.oauthOptions.loginBaseUri +
            this.securityConfig.oauthOptions.loginTokenPath;

        var data = 'grant_type=password&username=' + username +
            '&password=' + password +
            '&client_id=' + encodeURIComponent(this.securityConfig.oauthOptions.client_id);
        //Token servise request - form-data
        this.$http({
            method: 'POST',
            url: tokenPath,
            data: data,
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).success(function (result) {
            deferred.resolve({
                username: username,
                token: result.access_token,
                refresh_token: result.refresh_token
            });
        }).catch(function (err) {
            deferred.reject(err.data);
        });

        return deferred.promise;
    },
    //Login modal ekranını goster
    showLogInModal: function () {
        var self = this;
        //Ekrandami ?
        if (this.loginShowing) {
            return this.$q.when(null);
        }
        //Login ekranda flag
        this.loginShowing = true;
        //Scope credentials
        var scope = this.$rootScope.$new(true);
        scope.credentials = {};
        //Login ekranını goster
        return this.modal.showStdPopup(scope, this.localization.get('Giris'),
            this.securityConfig.loginTemplateUrl || this.defaultLoginTemplate, function (e) {
                //Validation
                if (self.common.isNullOrEmpty(scope.credentials.username) ||
                    self.common.isNullOrEmpty(scope.credentials.password)) {
                    e.preventDefault();
                    self.plugins.showToast(self.localization.get('KullaniciPasswordGiriniz'));
                } else {
                    //Login OAuth
                    return self.logIn(scope.credentials.username, scope.credentials.password);
                }
            }, true).finally(function () {
                self.loginShowing = false;
            });
    },
    //#endregion

    //#region UnAuthorized Action
    //Yetkisiz işlem gercekleştigi zaman bu method çalişiyor.(Bkz : Interceptor,initSecurity method)
    handleUnAuthorized: function () {
        var self = this;
        return this.showLogInModal().then(function (data) {
            //Login ekranından donen User model bilgisini handle eder
            //Parametre olarak userModel geciliyor
            self.handleUserModel(data);
        }, function (error) {
            if (error === 'CANCELLED') {
                //Cancel Butonnu tiklandi
                //Tum bekleyen requedtleri iptal et
                self.retryQueue.rejectAll();
                //Eger allowAnonymousAccess false ise direk cik
                if (!self.securityConfig.allowAnonymousAccess) {
                    //cik
                    ionic.Platform.exitApp();
                }
            } else {
                self.plugins.showToast(error.error_description);
            }
        });
    },
    //#endregion

Using preventDefault in button ontap events and also popup.close method together solved my issue.

function (e) {
                e.preventDefault();  
                //Validation
                if (self.common.isNullOrEmpty(scope.credentials.username) ||
                    self.common.isNullOrEmpty(scope.credentials.password)) {
                    self.plugins.showToast(self.localization.get('KullaniciPasswordGiriniz'));
                } else {
                    //Login OAuth
                    self.logIn(scope.credentials.username, scope.credentials.password).then(function (data) {
                        scope.popup.close(data);
                    }, function (error) {
                        self.plugins.showToast(error.error_description);
                    });
                }