Angular Http Get 404 停止进一步调用
Angular Http Get 404 Stops Further Calls
这是大头钉。我有这个服务电话
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 = [];
);
它的背面是这样的
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);
}
如果使用您的搜索词找不到内容,我调用的服务将 return 返回 404。如果我收到 404 错误,搜索将完全停止,我必须刷新页面才能进行另一次搜索。如果搜索成功,我可以在我的搜索框中重新输入,它会再次调用。
总结:当服务调用 404s 时,它似乎阻止了任何其他调用
感谢任何帮助。
您应该捕获 scryfallService 抛出的任何错误,并且 return 一个可以进一步处理的值。否则 observable 将完成。
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 = [];
);
这是大头钉。我有这个服务电话
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 = [];
);
它的背面是这样的
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);
}
如果使用您的搜索词找不到内容,我调用的服务将 return 返回 404。如果我收到 404 错误,搜索将完全停止,我必须刷新页面才能进行另一次搜索。如果搜索成功,我可以在我的搜索框中重新输入,它会再次调用。
总结:当服务调用 404s 时,它似乎阻止了任何其他调用
感谢任何帮助。
您应该捕获 scryfallService 抛出的任何错误,并且 return 一个可以进一步处理的值。否则 observable 将完成。
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 = [];
);