Add Deprecation
headers on deprecated endpoints (#34262)
Co-authored-by: Damien Mathieu <42@dmathieu.com>
This commit is contained in:
parent
40bb8ec325
commit
38f5e74122
10 changed files with 121 additions and 12 deletions
|
@ -1,4 +1,9 @@
|
|||
import type { AxiosResponse, Method, RawAxiosRequestHeaders } from 'axios';
|
||||
import type {
|
||||
AxiosError,
|
||||
AxiosResponse,
|
||||
Method,
|
||||
RawAxiosRequestHeaders,
|
||||
} from 'axios';
|
||||
import axios from 'axios';
|
||||
import LinkHeader from 'http-link-header';
|
||||
|
||||
|
@ -41,7 +46,7 @@ const authorizationTokenFromInitialState = (): RawAxiosRequestHeaders => {
|
|||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default function api(withAuthorization = true) {
|
||||
return axios.create({
|
||||
const instance = axios.create({
|
||||
transitional: {
|
||||
clarifyTimeoutError: true,
|
||||
},
|
||||
|
@ -60,6 +65,22 @@ export default function api(withAuthorization = true) {
|
|||
},
|
||||
],
|
||||
});
|
||||
|
||||
instance.interceptors.response.use(
|
||||
(response: AxiosResponse) => {
|
||||
if (response.headers.deprecation) {
|
||||
console.warn(
|
||||
`Deprecated request: ${response.config.method} ${response.config.url}`,
|
||||
);
|
||||
}
|
||||
return response;
|
||||
},
|
||||
(error: AxiosError) => {
|
||||
return Promise.reject(error);
|
||||
},
|
||||
);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
type RequestParamsOrData = Record<string, unknown>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue