How to throw an observable error manually?

后端 未结 8 1473
慢半拍i
慢半拍i 2020-12-02 16:35

I am working on an Angular app in which I am making a rest call through HTTP as below:

login(email, password) {
    let headers = new Headers();
    headers.a         


        
8条回答
  •  無奈伤痛
    2020-12-02 17:10

    Most of my issues were related to the imports, so here's the code that worked for me...

    import {_throw} from 'rxjs/observable/throw';
    login(email, password) {
    ...
        return this.http.post(`${this._configService.getBaseUrl()}/login`, body, options)
        .map((res: any) => {
    ...
            if (response.success == 0) {
               _throw(response);  
            } else if (response.success == 1) {
    ...
            }
        });
    }
    

    This will be the solution if you are facing errors like...

    ERROR TypeError: WEBPACK_IMPORTED_MODULE_2_rxjs_Observable.Observable.throw is not a function

提交回复
热议问题