I am creating an Angular Http Retry Interceptor. When I have retries of 1, my code looks like this:
return next.handle(req).pipe(
retryWhen((error) => {
return error.pipe(
delay(1000),
take(1),
concatMap((err) => {
return _throw({ ...err, message: `Sorry, there was an error (after 1 retry)` });
})
);
})
);
This seems to work. I can throw with the original error.
Now, when the retries is zero, this doesn't work. I think that's because we are doing take(0). However, the concat operator will work:
return next.handle(req).pipe(
retryWhen((error) => {
return error.pipe(
delay(1000),
take(0),
concat(_throw({ message: `Sorry, there was an error (after 0 retries)` }))
);
})
);
But the problem is that I can't get the original error. What other operators can I use in my zero retry scenario to get/throw the original error?