mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 12:50:09 +00:00
Add retry logic with exponential backoff to AudibleService
Introduces a fetchWithRetry method to handle network errors and rate limiting (503, 429) with exponential backoff in AudibleService. Updates getPopularAudiobooks and getNewReleases to use this retry logic and improves error handling to stop pagination on errors but return collected results. Test cases are updated to use non-retryable errors (404) for more accurate coverage.
This commit is contained in:
@@ -355,7 +355,10 @@ describe('AudibleService', () => {
|
||||
|
||||
it('returns empty popular audiobooks on errors', async () => {
|
||||
configServiceMock.getAudibleRegion.mockResolvedValue('us');
|
||||
clientMock.get.mockRejectedValue(new Error('boom'));
|
||||
// Use 404 error which is not retryable
|
||||
const error: any = new Error('Not Found');
|
||||
error.response = { status: 404 };
|
||||
clientMock.get.mockRejectedValue(error);
|
||||
|
||||
const service = new AudibleService();
|
||||
const results = await service.getPopularAudiobooks(5);
|
||||
@@ -365,7 +368,10 @@ describe('AudibleService', () => {
|
||||
|
||||
it('returns empty new releases on errors', async () => {
|
||||
configServiceMock.getAudibleRegion.mockResolvedValue('us');
|
||||
clientMock.get.mockRejectedValue(new Error('boom'));
|
||||
// Use 404 error which is not retryable
|
||||
const error: any = new Error('Not Found');
|
||||
error.response = { status: 404 };
|
||||
clientMock.get.mockRejectedValue(error);
|
||||
|
||||
const service = new AudibleService();
|
||||
const results = await service.getNewReleases(5);
|
||||
|
||||
Reference in New Issue
Block a user