Skip to content

Commit b27f02a

Browse files
authored
PD-5437 (#2814)
1 parent 446e79c commit b27f02a

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/app/core/http/retry-transient.interceptor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Injectable } from '@angular/core'
99
import { Observable, timer } from 'rxjs'
1010
import { retry } from 'rxjs/operators'
1111

12-
const RETRYABLE_HTTP_STATUSES = new Set([408, 502, 503, 504])
12+
const RETRYABLE_HTTP_STATUSES = new Set([0, 408, 502, 503, 504])
1313
const MAX_RETRIES = 2
1414

1515
@Injectable()

src/app/core/http/retry-transient.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,32 @@ import { defer, of, throwError } from 'rxjs'
33
import { retryTransient } from './retry-transient'
44

55
describe('retryTransient', () => {
6+
it('retries up to the max retries for HTTP status 0', (done) => {
7+
let attempts = 0
8+
const source$ = defer(() => {
9+
attempts++
10+
if (attempts <= 2) {
11+
return throwError(
12+
() =>
13+
new HttpErrorResponse({
14+
status: 0,
15+
statusText: 'Network error',
16+
})
17+
)
18+
}
19+
return of('ok')
20+
})
21+
22+
source$.pipe(retryTransient(2)).subscribe({
23+
next: (value) => {
24+
expect(value).toBe('ok')
25+
expect(attempts).toBe(3)
26+
done()
27+
},
28+
error: done.fail,
29+
})
30+
})
31+
632
it('retries up to the max retries for retryable HTTP statuses', (done) => {
733
let attempts = 0
834
const source$ = defer(() => {

src/app/core/http/retry-transient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { HttpErrorResponse } from '@angular/common/http'
22
import { MonoTypeOperatorFunction, timer } from 'rxjs'
33
import { retry } from 'rxjs/operators'
44

5-
export const RETRYABLE_HTTP_STATUSES = new Set([408, 502, 503, 504])
5+
export const RETRYABLE_HTTP_STATUSES = new Set([0, 408, 502, 503, 504])
66

77
export function retryTransient<T>(
88
maxRetries = 2,

0 commit comments

Comments
 (0)