From f4a1e065f2a58278850f26259468a9f1153093c1 Mon Sep 17 00:00:00 2001 From: kleinfreund Date: Sat, 25 Nov 2023 20:09:38 +0100 Subject: [PATCH] fix: only processing the first response success handler Fixes an issue with response success handlers where only the first handler was processed. --- src/retrieve.test.ts | 16 ++++++++++++++++ src/retrieve.ts | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/retrieve.test.ts b/src/retrieve.test.ts index 4e42844..ef1dde1 100644 --- a/src/retrieve.test.ts +++ b/src/retrieve.test.ts @@ -955,6 +955,22 @@ describe('retrieve', () => { } satisfies RetrieveConfig, 'test', ], + [ + { + url: 'http://example.org', + responseSuccessHandlers: [ + (retrieveResponse) => { + retrieveResponse.data = 'test' + return Promise.resolve(retrieveResponse) + }, + (retrieveResponse) => { + retrieveResponse.data = 'overridden data' + return Promise.resolve(retrieveResponse) + }, + ], + } satisfies RetrieveConfig, + 'overridden data', + ], ])('onResponseSuccess handlers produce response', async (config: RetrieveConfig, expectedData: unknown) => { vi.spyOn(global, 'fetch').mockImplementation(() => Promise.resolve(new Response('OK'))) diff --git a/src/retrieve.ts b/src/retrieve.ts index a8c95be..ed72622 100644 --- a/src/retrieve.ts +++ b/src/retrieve.ts @@ -313,10 +313,10 @@ export async function retrieve(config: RetrieveConfig): Promise