@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