Skip to content

Commit

Permalink
fix(cb2-13831): retry on status of 0 (#1622)
Browse files Browse the repository at this point in the history
* fix(cb2-13831): retry on status of 0

* fix(cb2-13831): add unit test to mock unknown response situation
  • Loading branch information
pbardy2000 authored Oct 14, 2024
1 parent 9f9ffa7 commit cfa0937
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,36 @@ describe('DelayedRetryInterceptor', () => {
flush();
}));
});

describe('Http failure response for x: 0 Unknown Error', () => {
beforeEach(() => {
TestBed.overrideProvider(HTTP_RETRY_CONFIG, {
useValue: { delay: 500, count: 3, httpStatusRetry: [0, 504], whiteList: [DUMMY_ENDPOINT] },
});
client = TestBed.inject(HttpClient);
httpTestingController = TestBed.inject(HttpTestingController);
interceptor = TestBed.inject(DelayedRetryInterceptor);
});

afterEach(() => {
// After every test, assert that there are no more pending requests.
httpTestingController.verify();
});

it('should handle response codes of 0 (Unknown Error) by retrying the request', fakeAsync(() => {
client.get(DUMMY_ENDPOINT).subscribe({
error: (e) => {
expect(e).toEqual(new Error('Request timed out. Check connectivity and try again.'));
},
});

const retryCount = 3;
for (let i = 0; i < retryCount; i++) {
tick(500 * (i + 1));
const req = httpTestingController.expectOne(DUMMY_ENDPOINT);
req.flush('Deliberate 0 error', { status: 0, statusText: 'Unknown error' });
}
flush();
}));
});
});
2 changes: 1 addition & 1 deletion src/app/interceptors/interceptor.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ErrorInterceptorModule } from './error-handling/error-handling.module';
DelayedRetryModule.forRoot({
count: 3,
delay: 2000,
httpStatusRetry: [504],
httpStatusRetry: [0, 504],
backoff: true,
whiteList: ['document-retrieval'],
}),
Expand Down

0 comments on commit cfa0937

Please sign in to comment.