Get The Response Status From An Axios Error
async function getCharacter(characterId) {
let response;
try {
response = await axios.get(
`https://rickandmortyapi.com/api/character/${characterId}`
);
} catch (e) {
response = e.response;
}
console.log(response.status);
// You can also access the response data
// console.log(response.data);
}
getCharacter(2);
//=> 200
getCharacter(2000);
//=> 404Last updated