Using RxJS 6.5, I subscribe to a stream and I'd like to take two distinct actions: - one when the source errors - another when the source takes too long to send data (timeout)
Here is what I currently have
source$.pipe(
timeoutWith(5000, log('timeout!')),
catchError(log('error!'))
).subscribe();
function log(msg) {
console.log(msg);
return of(null);
}
When my source takes longer than 5000ms to emit, I get the expected result: timeout!
However when my source throws an error early (before the 5000ms), both lines execute. It seems as though it timeoutWith is triggered whenever the source did not emit, even if it errored.
How can I set up a pipe so that the timeout logic only runs if time has actually elapsed, not because the stream was aborted due to an error?