xxxxxxxxxx
catch (error) {
if ((error as AxiosError).response?.status === 404) {
setJobListError('Error type 404'))
}
xxxxxxxxxx
try {
await axios.get('/bad-call')
} catch (error) {
const err = error as AxiosError
if (err.response) {
console.log(err.response.status)
console.log(err.response.data)
}
this.handleAxiosError(error)
}
xxxxxxxxxx
axios.get('/api/xyz/abcd')
.catch(function (error) {
if (error.response) {
// Request made and server responded
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
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
}
});
xxxxxxxxxx
try {
const { data } = await axios({
method: 'put',
url: '/api/article/123',
data: {
title: 'Making PUT Requests with Axios',
status: 'published'
}
});
console.log(data);
} catch (err) {
if (err.response.status === 404) {
console.log('Resource could not be found!');
} else {
console.log(err.message);
}
}
xxxxxxxxxx
this issue happen when your response have an error , for example when the response is correct but in the then response you do something that throw an error , axios then catch that error , even if the response from the server was success