I've coded this http calling method:
public exists(id: string): Observable<boolean> {
const buildURL = () => map((userId: string) => this.buildIdURL(userId));
const buildResponse = () => map(() => true);
const onErrorGetDetails = <T>() => catchError<T, boolean>((error: Response) => this.handleError(error));
const makeRequest = () => switchMap((url: string) => this.authHttp.head(url));
return Observable.of(id)
.pipe(
buildURL(),
makeRequest(),
buildResponse(),
onErrorGetDetails()
);
}
So, I'm trying to handle when response is:
- an 404, I need to return an
Observable.of(false) - or otherwise, return an
Observable.throw(error).
Any ideas?
handleErroris what I'm trying to code.httpraises an error. So,onErroris emitted in observable.