Skip to content

Commit

Permalink
fix: correct config re throw
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Jul 30, 2023
1 parent 929054e commit ddcac5f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/interceptors/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ export function defaultResponseInterceptor(
msg: 'Response interceptor received an unknown response.',
data: response
});

throw response;
}

// Re-throws the error
throw response;
}

const id = (response.id = response.config.id ??= axios.generateKey(response.config));
Expand Down
3 changes: 2 additions & 1 deletion test/interceptors/stale-if-error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ describe('Last-Modified handling', () => {
id,
adapter: (config) =>
Promise.reject({
isAxiosError: true,
data: false,
headers: {},
config,
Expand Down Expand Up @@ -397,6 +398,6 @@ describe('Last-Modified handling', () => {
cache: { staleIfError: true },
validateStatus: () => false
})
).rejects.toMatchObject({ id });
).rejects.toMatchObject({ config: { id } });
});
});
15 changes: 8 additions & 7 deletions test/mocks/axios.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Axios from 'axios';
import type { AxiosCacheInstance, CacheRequestConfig } from '../../src/cache/axios';
import Axios, { AxiosError } from 'axios';
import type { AxiosCacheInstance } from '../../src/cache/axios';
import { CacheOptions, setupCache } from '../../src/cache/create';
import { Header } from '../../src/header/headers';

Expand All @@ -22,11 +22,12 @@ export function mockAxios(
const statusText = should304 ? '304 Not Modified' : '200 OK';

if (config.validateStatus?.(status) === false) {
throw {
id: (config as CacheRequestConfig).id,
throw new AxiosError(
'request failed',
status.toString(),
config,
request: { config },
response: {
{ config },
{
data: true,
status,
statusText,
Expand All @@ -38,7 +39,7 @@ export function mockAxios(
config,
request: { config }
}
};
);
}

return {
Expand Down

0 comments on commit ddcac5f

Please sign in to comment.