In my angular 6 application, I have a problem with some rxjs operators. I have a search field and I need to call my service (service do GET request) when the user is typing in the field, it is working if the service doesn't have any errors like 500.
But a request with 500 error break the chain in the value change, probably I don't return the correct value from the service...
this is the search field in the component:
this.manufacturer.valueChanges
.pipe(
filter((value: string) => (value ? value.length > 2 : false)),
tap(() => (this.loadingAutocomplete = true)),
debounceTime(500),
switchMap(val => this.frameService.getItems(val, "manufacturerAutocomplete")),
tap(() => (this.loadingAutocomplete = false)),
catchError(err =>
return of([]))
)
.subscribe(
manufacturers => {
this.matchingManufacturers.next(manufacturers);
},
err => {
this.loadingAutocomplete = false;
this.matchingManufacturers.next([]);
}
);
And this is the service:
getItems(value: string, endPoint: string) {
return this.http.get(
this.endPointUrlService.cutLinks(this.endPointUrlService.map.get("frames")) + "/search/" + endPoint
).pipe(
map((res: string[]) => {
if (res) {
return res;
} else {
return [];
}
})
);
}
First time user types something it works, if I have an erros the valueChanges is not invoked again. I need to handle the errors in the component, not in the service.