I have created this HTTP request method:
public isExisting(id: string): Observable<boolean> {
const createURL = () => map((userId: string) => this.createIdURL(userId));
const createResponse = () => map(() => true);
const handleErrorResponse = <T>() => catchError<T, boolean>((error: Response) => this.handleError(error));
const sendRequest = () => switchMap((url: string) => this.authHttp.head(url));
return Observable.of(id)
.pipe(
createURL(),
sendRequest(),
createResponse(),
handleErrorResponse()
);
}
Now, I want to manage the response in the following cases:
- If the response is a 404 error, I should return
Observable.of(false)
- Otherwise, I should return
Observable.throw(error)
.
Any suggestions?