Getting error on ionic cordova build android

耗尽温柔 提交于 2019-12-01 19:37:23

问题


Just started to learn ionic 3. Getting below error on ionic cordova build android

(node:6364) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): [object Object]
(node:6364) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Below is my ionic info.

cli packages: (C:\Users\HIT\AppData\Roaming\npm\node_modules)

@ionic/cli-utils  : 1.19.0
ionic (Ionic CLI) : 3.19.0
global packages:

cordova (Cordova CLI) : 8.0.0
local packages:

@ionic/app-scripts : 3.1.6
Cordova Platforms  : none
Ionic Framework    : ionic-angular 3.9.2
System:

Node : v8.5.0
npm  : 5.3.0
OS   : Windows 10
Environment Variables:

ANDROID_HOME : D:\AndroidSdk\platform-tools
Misc:

backend : pro

I wrote below promise code

 postData(credentials, type) {
    return new Promise((resolve, reject) => {
      let headers = new Headers();

      this.http.post(apiUrl+type, JSON.stringify(credentials), {headers: headers})
        .subscribe(res => {
          resolve(res.json());
        }, (err) => {
          reject(err);
        });
    });
  }

I call the postData function below

signup(){
    //Api connection
this.authService.postData(this.userData , "register.php").then((result) => {
    this.reposeData = result;
    console.log(this.reposeData);
    localStorage.setItem('userData' , JSON.stringify(this.reposeData))
    this.navCtrl.push(TabsPage);
}, (err) => {
    //connection failed
});

}

Is this my code issue?


回答1:


According to the error message, you have not handled a rejection on one of your Promise objects. Each and every promise is expected to have a .catch(...).

var flag = false;
var Test = function () {
return new Promise(function (resolve, reject) {
if (flag === true)
    resolve();
else
    reject();
});
}
var testFunc = Test();
testFunc.then(function () {
 alert("Promise Resolved");
});
testFunc.catch(function () {
 alert("Promise Rejected");
});

Read more about Promise Objects here



来源:https://stackoverflow.com/questions/48145380/getting-error-on-ionic-cordova-build-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!