I'm sorry to ask like this, but I'm pretty much an Angular noob and stuck with fixing someone else's code, who, I'm afraid, is not that experienced with Angular either.
Here is the code
const searchTermStream = this.searchTerm.valueChanges
.debounceTime(400)
.filter(query => query.length > 2 || query.length === 0)
.do(query => this.adjustBrowserUrl(query))
.distinctUntilChanged()
.switchMap(query => this.itemService.findItems(query))
.subscribe()
;
const paramsStream = this.route.queryParams
.map(params => decodeURI(params['query'] || ''))
.do(query => this.searchTerm.setValue(query))
.distinctUntilChanged()
.switchMap(query => this.itemService.findItems(query))
.subscribe()
;
this.itemList$ = this.itemService.items$;
this.itemCount$ = this.itemService.countAllItems();
Apparently this code makes rest calls and retrieves items and itemCount from a backend and also filters if query is provided.
The problem is when the first call fails (session timeout) the other calls are still being executed and cause exceptions in the backend, the exceptions are handled properly, but the calls are still unwanted.
So I need to figure out now how to make the calls sequentially and stop the calls altogether if the first one fails (for whatever reasons). I've found some examples on the net and on here using promises and observables, but since I'm a noob I have a bit trouble making heads or tails of it and adapting those for my purposes.
Any help would be greatly appreciated.