Skip to content

Commit a71bed1

Browse files
authored
fix: unmarshal the value returned by the responseError interceptor (#650)
1 parent 8b443f4 commit a71bed1

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

packages/clients/src/scw/fetch/__tests__/build-fetcher.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,30 @@ describe(`buildFetcher (mock)`, () => {
159159
).resolves.toBe(42)
160160
})
161161

162+
it('gets the unmarshalled value of what responseError returns', () => {
163+
mockedFetch.mockRejectedValue(new TypeError(''))
164+
165+
return expect(
166+
buildFetcher(
167+
{
168+
...DEFAULT_SETTINGS,
169+
interceptors: [
170+
{
171+
responseError: () => Promise.resolve(42),
172+
},
173+
],
174+
},
175+
global.fetch,
176+
)(
177+
{
178+
method: 'GET',
179+
path: '/will-trigger-an-error',
180+
},
181+
data => `${typeof data === 'number' ? data : ''}-dummy-output`,
182+
),
183+
).resolves.toBe('42-dummy-output')
184+
})
185+
162186
it('gets modified request in response error', () => {
163187
mockedFetch.mockRejectedValue(new TypeError(''))
164188

packages/clients/src/scw/fetch/build-fetcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const buildFetcher = (settings: Settings, httpClient: typeof fetch) => {
112112
const resErrorInterceptors = prepareResponseErrors()
113113
const handledError = (await resErrorInterceptors(finalRequest, err)) as T
114114

115-
return handledError
115+
return unwrapper(handledError)
116116
}
117117
}
118118
}

0 commit comments

Comments
 (0)