Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70894

Returning http response for error

$
0
0

@newelement wrote:

Trying to get http response to return even when an error occurs.

login( creds ){

  var headers = new Headers();
  headers.append('Content-Type', 'application/x-www-form-urlencoded');

  return new Promise(resolve => {
    this.http.post( this.baseUrl+'/login', creds, {
        headers: headers
    })
      .map(res => res.json())
      .subscribe(
        data => {
        this.data = data;
        this.saveToken(data.api_token);
        resolve(this.data);
        },
        error => { resolve({success: false}) }
        ).catch( resolve({success: false}) );
  });
 }

Here is the call

this.auth.login( creds ).then(function( res ){
     if(res.success){
         t.gotoStart();
     } else {
         console.log(failed);
         t.failedAlert('Login Failed', 'Either your email or password was incorrect.')
     }
 });

Posts: 6

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 70894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>