简体   繁体   中英

What is the return type of Http.get().catch?

I'm currently learning angular 2, taking Deborah Kurata's Pluralsight class (Angular 2: Getting Started). It's great so far, but, for the life of me, I can't seem to discover what the return type of my .catch should be. In her course, and in every example I've found so far, the return type is left blank.

This is what I have:

getProducts(): Observable<IProduct[]> {
    return this._http.get("someurl")
        .map {.....}
        .catch(this.handleError);
}

handleError (response: Response) **/*what goes here?*/** {
    // the code in the course says Observable.throw, but chrome is
    // complaining that there is no such function. I have tracked 
    // down "static throw: typeof ErrorObservable.create;" in 
    // Observable.ts but I'm not sure what's going on here.
}

The most common return type is an Observable .

To be precise, the selector function to the catch() operator is defined as:

(err: any, caught: Observable): ObservableInput

The returned Observable is subscribed using the subscribeToResult which supports multiple return types (that's why there's ObservableInput and not just Observable ). Anyway, it's easier to have a look at the examples in the source code that aren't in the online documentation yet where you should be able to understand how it works: https://github.com/ReactiveX/rxjs/blob/master/src/operator/catch.ts#L8

Or see what subscribeToResult supports: https://github.com/ReactiveX/rxjs/blob/master/src/util/subscribeToResult.ts#L17

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM