mirror of
https://github.com/arthurfiorette/axios-cache-interceptor.git
synced 2025-12-08 17:36:16 +00:00
fix: correct config re throw
This commit is contained in:
parent
929054e83f
commit
ddcac5f58f
@ -39,9 +39,10 @@ export function defaultResponseInterceptor(
|
|||||||
msg: 'Response interceptor received an unknown response.',
|
msg: 'Response interceptor received an unknown response.',
|
||||||
data: response
|
data: response
|
||||||
});
|
});
|
||||||
|
|
||||||
throw response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Re-throws the error
|
||||||
|
throw response;
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = (response.id = response.config.id ??= axios.generateKey(response.config));
|
const id = (response.id = response.config.id ??= axios.generateKey(response.config));
|
||||||
|
|||||||
@ -268,6 +268,7 @@ describe('Last-Modified handling', () => {
|
|||||||
id,
|
id,
|
||||||
adapter: (config) =>
|
adapter: (config) =>
|
||||||
Promise.reject({
|
Promise.reject({
|
||||||
|
isAxiosError: true,
|
||||||
data: false,
|
data: false,
|
||||||
headers: {},
|
headers: {},
|
||||||
config,
|
config,
|
||||||
@ -397,6 +398,6 @@ describe('Last-Modified handling', () => {
|
|||||||
cache: { staleIfError: true },
|
cache: { staleIfError: true },
|
||||||
validateStatus: () => false
|
validateStatus: () => false
|
||||||
})
|
})
|
||||||
).rejects.toMatchObject({ id });
|
).rejects.toMatchObject({ config: { id } });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import Axios from 'axios';
|
import Axios, { AxiosError } from 'axios';
|
||||||
import type { AxiosCacheInstance, CacheRequestConfig } from '../../src/cache/axios';
|
import type { AxiosCacheInstance } from '../../src/cache/axios';
|
||||||
import { CacheOptions, setupCache } from '../../src/cache/create';
|
import { CacheOptions, setupCache } from '../../src/cache/create';
|
||||||
import { Header } from '../../src/header/headers';
|
import { Header } from '../../src/header/headers';
|
||||||
|
|
||||||
@ -22,11 +22,12 @@ export function mockAxios(
|
|||||||
const statusText = should304 ? '304 Not Modified' : '200 OK';
|
const statusText = should304 ? '304 Not Modified' : '200 OK';
|
||||||
|
|
||||||
if (config.validateStatus?.(status) === false) {
|
if (config.validateStatus?.(status) === false) {
|
||||||
throw {
|
throw new AxiosError(
|
||||||
id: (config as CacheRequestConfig).id,
|
'request failed',
|
||||||
|
status.toString(),
|
||||||
config,
|
config,
|
||||||
request: { config },
|
{ config },
|
||||||
response: {
|
{
|
||||||
data: true,
|
data: true,
|
||||||
status,
|
status,
|
||||||
statusText,
|
statusText,
|
||||||
@ -38,7 +39,7 @@ export function mockAxios(
|
|||||||
config,
|
config,
|
||||||
request: { config }
|
request: { config }
|
||||||
}
|
}
|
||||||
};
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user