Я прочитал следующие вопросы, но не смог найти решение.
Я хочу получить ошибки 400, 500, ... кто-то сказал, что вы должны поймать тогда, но я попробовал, и ничего не произошло. для теста я написал функцию для получения ошибки 404, 400, ...
export const myAxios = url => {
Axios.get(url)
.then(response => {
// Success
console.log("then response ", response);
})
.catch(error => {
// Error
if (error.response) {
console.log("error respone", error.response);
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
// console.log(error.response.data);
// console.log(error.response.status);
// console.log(error.response.headers);
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the
// browser and an instance of
// http.ClientRequest in node.js
console.log("erros request: ", error.request);
} else {
// Something happened in setting up the request that triggered an Error
console.log("Error message", error.message);
}
console.log("errors config : ", error.config);
});
};
ax ios не ловит ошибки, и консоль браузера регистрирует это:
xhr.js:172 GET http://localhost:3000/app/..../choices 404 (Not Found)
dispatchXhrRequest @ xhr.js:172
xhrAdapter @ xhr.js:11
dispatchRequest @ dispatchRequest.js:59
Promise.then (async)
request @ Axios.js:53
Axios.<computed> @ Axios.js:68
wrap @ bind.js:9
myAxios @ textaxios.js:4
(anonymous) @ List.jsx:14
commitHookEffectList @ react-dom.development.js:22030
Any советы или помощь будут оценены.
пакетов:
"axios": "^0.19.0"
"react": "^16.12.0"