I am using the Axios in react app to send the HTTP request. but how to differentiate for the runtime error or the HTTP error in the catch block.
axios.get(getCertUrl)
.then(async (response) => {
// operation might result in run time error.
})
.catch(async (error) => {
// if (only error related to http) {
} else {
// other error related not related to http eg, null refrence
}
});
You can easily differentiate between HTTP errors and other run-time errors.HTTP error codes are present in error.response.status and for others, I think you can log them and check their type. Here is a reference to how to get HTTP errors.axios HTTP errors