Я хочу добавить перехватчик ошибок в response. Запросы шлю при помощи axios. Сделать это хочу через interceptors. Вопрос такой: как мне не описывать interceptors для каждого fetch, а сделать это в одном месте?
import axios from 'axios';
export const fetchProfile = axios.create({
baseURL: '/profile',
headers: {
'Content-Type': 'application/json',
'Authorization': process.env.TOKEN,
},
withCredentials: true,
});
export const fetchCart = axios.create({
baseURL: '/cart',
headers: {
'Content-Type': 'application/json',
'Authorization': process.env.TOKEN,
},
withCredentials: true,
});
export const fetchCatalogs = axios.create({
baseURL: '/catalogs',
headers: {
'Content-Type': 'application/json',
'Authorization': process.env.TOKEN,
},
withCredentials: true,
});
export const fetchOrders = axios.create({
baseURL: '/orders',
headers: {
'Content-Type': 'application/json',
'Authorization': process.env.TOKEN,
},
withCredentials: true,
});
fetchOrders.interceptors.response.use(response => {
console.log('yeeeeeeeeeeeeeeeeeeeeeeeee');
console.log(response);
return response;
}, error => {
console.log('fuuuuuuuuuuuu');
console.log(error);
return Promise.reject(error);
});
export const fetchProducts = axios.create({
baseURL: '/products',
headers: {
'Content-Type': 'application/json',
'Authorization': process.env.TOKEN,
},
withCredentials: false,
});