This is not related to a bug I am encountering, but rather a syntax issue.
The workflow is simple :
- make an HTTP request that returns a boolean
- if the boolean is true, then continue
- if the boolean is false, log a warning, and stop the stream.
To manage that, my current code is this :
Boilerplate
private _getBoolean() { return this.http.get(...); }
private _getData() { return this.http.get(...); }
Current code
public getData() {
return this._getBoolean().pipe(
filter(bool => {
if(!bool) {
console.warn('Wrong server answer, stream stopped');
return false;
}
return true;
}),
switchMap(bool => this._getData())
);
}
And I don't know why, but it doesn't feel natural and optimized to me.
I thought that there would be something that simplifies the syntax, something like this
public getData() {
return this._getBoolean().pipe(
throwError(bool => bool ? new Error('Wrong server answer, stream stopped') : null),
catchError(err => console.warn(err)),
switchMap(bool => this._getData())
);
}
Is there something along the lines of that, or do I have the correct syntax ?