Observed error message. Unable to catch subscription

I am using RXJS for Observation with Angular 4

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

      

My function looks like this

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 function subscribes in my service like this

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

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

      

For some reason, I cannot get errors. Can someone please advise hw to throw the error? Pls help.

+3


source to share


1 answer


Instead, return Observable.throw("...");

you should use:



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

      

+2


source







All Articles