diff --git a/src/interceptors/response.ts b/src/interceptors/response.ts index f7e1957..f160c9a 100644 --- a/src/interceptors/response.ts +++ b/src/interceptors/response.ts @@ -32,6 +32,18 @@ export function defaultResponseInterceptor( }; const onFulfilled: ResponseInterceptor['onFulfilled'] = async (response) => { + // When response.config is not present, the response is indeed a error. + if (!response.config) { + if (__ACI_DEV__) { + axios.debug?.({ + msg: 'Response interceptor received an unknown response.', + data: response + }); + + throw response; + } + } + const id = (response.id = response.config.id ??= axios.generateKey(response.config)); response.cached ??= false; diff --git a/test/interceptors/response.test.ts b/test/interceptors/response.test.ts index f2d3628..1b9c1bf 100644 --- a/test/interceptors/response.test.ts +++ b/test/interceptors/response.test.ts @@ -252,4 +252,20 @@ describe('test response interceptor', () => { expect(cache.state).not.toBe('loading'); expect(cache.state).toBe('empty'); }); + + it('expects response interceptor handles non response errors', async () => { + const instance = Axios.create(); + + const NOT_RESPONSE = { notAResponse: true }; + + //@ts-expect-error - this is indeed wrongly behavior + instance.interceptors.response.use(() => NOT_RESPONSE); + + const axios = mockAxios(undefined, undefined, instance); + + await expect( + // just calls the response interceptor + axios.get('url') + ).rejects.toBe(NOT_RESPONSE); + }); });