Reputation: 190
Here is the brass tacks. I have this service call
this.searchTerm.valueChanges.debounceTime(400)
.filter(searchTerm => { return searchTerm.length >= 3;})
.distinctUntilChanged()
.switchMap((searchTerm) => this._scryfallService.getCards(searchTerm))
.subscribe(data => this.cardSearchResults = data.data,
err => this.cardSearchResults = [];
);
And the back side of it looks like this
getCards(term: string): Observable<any> {
let url = this.scryFallEndpoint + 'search?q="' + encodeURI(term) + '"+unique:prints+not:digital' ;
return this._http.get(url)
.map(res => res);
}
The service I make calls to will return a 404 if it can't find something using your search terms. If I get a 404 error the search stops working entirely and I have to refresh the page to do another search. If the search is successful I can just retype in my search box and it does another call just fine.
Summary: When the service call 404s it seems to prevent any other calls from being made
Any help is appreciated.
Upvotes: 1
Views: 471
Reputation: 462
you should catch any error that the scryfallService throws and return a value that can be handled futher on. otherwise the observable will complete.
this.searchTerm.valueChanges.debounceTime(400)
.filter(searchTerm => { return searchTerm.length >= 3;})
.distinctUntilChanged()
.switchMap((searchTerm) => this._scryfallService.getCards(searchTerm).catch(err => Observable.of('error happened but please continue')))
.subscribe(data => this.cardSearchResults = data.data,
err => this.cardSearchResults = [];
);
Upvotes: 2