How to throw observable error manually in angular2? : <p>I am working on angular2 app in which I am making a rest call through HTTp as below:</p>

<pre><code>login(email, password) {
    let headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded');
    let options = new RequestOptions({ headers: headers });
    let body = `identity=${email}&amp;password=${password}`;
    return this.http.post(`${this._configService.getBaseUrl()}/login`, body, options)
    .map((res: any) =&gt; {
        let response: any = JSON.parse(res._body);
        if (response.success == 0) {
          Observable.throw(response);  // not working
        } else if (response.success == 1) {
          console.log('success');
          localStorage.setItem('auth_token', 'authenticated');
          this.loggedIn = true;
          return response;
        }
    });
}
</code></pre>

<p>basically I want my component to get response &amp; error in my subscribe call.</p>

<p>i.e.</p>

<pre><code>this._authenticateService.login(this.loginObj['identity'],this.loginObj['password']).subscribe(
  (success)=&gt;{      
    this.credentialsError=null;  
    this.loginObj={};  
    this._router.navigate(['dashboard']);    
  },
  (error)=&gt;{
    console.log(error);        
    this.credentialsError=error;     
  }
);
</code></pre>

<p>but my api always returns success as it id defined that way.</p>

<p>So I want to know how can I throw error msg if <code>response.success == 0</code> ,  so that it will be accessed inside error argument of my subscribe callback.</p>
