可观察的错误消息 - 无法捕获订阅

时间:2017-05-15 15:37:14

标签: angular rxjs

我正在使用带有Angular 4的RXJS观察

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/from';

我的功能如下

public temp(){
         return Observable.create(observer => {

            this.platform.ready().then(() => {
                this.sqlite.create({
                    name: 'offline.db',
                    location: 'default'
                }).then((db: SQLiteObject) => {
                    db.executeSql("select * from TEMP_INSTANCE WHERE CRE_BY=? AND AUD_NUMBER=? ", [localStorage.getItem("user_name"), localStorage.getItem("audNo")])                                               auditNumber]).then(
                        a => {      
                            if (a && a.rows && a.rows.length > 0) {
                                this._util.logData('instance already downloaded.' +  localStorage.getItem("audNo"));
                                return Observable.throw("Instance already downloaded for offline use");

                                } else {
                                         observer.next(true);
                                         observer.complete();

                                }
                        });

                });
            }); 
    }

此功能在我的服务中订阅如下

this._dbService.temp().subscribe(a =>{
                                    if(a){
                                        alert('Yet to download');

                                    }
                                },
                        error => {
                           alert('Error'+e);
                        });

出于某种原因,我无法得到错误。任何人都可以建议hw抛出错误?请帮助。

1 个答案:

答案 0 :(得分:1)

而不是return Observable.throw("...");你必须使用:

observer.error("Instance already downloaded for offline use");