在typescript中的Promise中处理null返回值

时间:2017-02-11 23:05:24

标签: javascript typescript

我对打字稿很新,并有以下问题。 我有以下代码,当console.log('uid....' + uid);为空时,我无法触及uid

    deleteUser(email: string): Promise<User> {
            let uid: string;
            let p = new Promise<User>((resolve) => {
                this.loginService.getUserIdByEmail(email).then((getUserResponse) => {


**********************************
    ******** do not reach here when getUserResponse is NULL**********************
************************


                    uid = getUserResponse;
                    console.log('uid....' + uid);
                    if (uid !== null) {
                        let actions = [
                            this.siteUserTableService.deleteByRowKey(uid),
                            this.userSiteTableService.deleteById(uid),
                        ];
                        Promise.all(actions.map(this.reflect)).then(values => {
                            this.tableService.deleteById(uid).then((deleteResponse) => {
                                this.loginService.deleteUserByEmail(email);
                            });
                        });
                    }

                }).catch((err) => {
                    // Something wrong
                });
            });
            return p;
        };




getUserIdByEmail(email: string): Promise<string> {
        let searchParams = {
            query: 'select UID from accounts where profile.email = "' + email + '"'
        };

        let p = new Promise<string>((resolve, reject) => {
        login.accounts.search(searchParams).then((response) => {
            if (response.errorCode === 0 && response.results.length > 0) {
                resolve(response.results[0].UID);
            } else {
                console.log('No login user...');
                reject('');
            }
        });
    });
    };

由于我没有从getUserIdByEmail函数获得返回值(返回null),因此无法继续使用deleteUser函数。

那么即使使用null返回值,我怎么能继续。

由于

0 个答案:

没有答案