When developing my Angular application, I encountered a situation where I needed to make an HTTP call to a backend server. To enhance its reliability, I decided to incorporate an interceptor to implement the retry pattern.
In the past, I utilized RxJS's retryWhen
operator for this purpose. However, since it has been deprecated, I had to find an alternative approach:
return next.handle(copiedRequest).pipe(
retry({
count: 5,
delay: 1000,
}),
catchError((error: HttpErrorResponse) => {
if (error.status === 0) {
// Server not responding, so handle accordingly
}
return throwError(() => error);
})
);
Despite successfully implementing retries for all HTTP response statuses, I realized that there are scenarios where retrying based on certain status codes is unnecessary. Is there a way to introduce a filter to the retry logic in order to determine whether or not retry should be attempted?