I am making a normal API call, but for some reason I don't see console.log(err) in my catch block
when I get 500 error. It always fires console.log(result) in my then block
What am I doing wrong?
const startHandler = () => {
setOpenLoadingModal(true);
fetch(url, {
method: 'post',
body: JSON.stringify(payload),
headers: headers,
})
.then((response) => response.json())
.then((result) => {
console.log(" ~ file: index.js ~ line 159 ~ .then ~ result", result)
const { client_id, token } = result;
if (!token || !client_id){
setOpenErrorModal(true);
return setOpenLoadingModal(false);
} else{
return history.push({
pathname: FORMS_URL.LANDING_PAGE,
});
})
.catch((err) => {
console.log(err)
setOpenErrorModal(true);
setOpenLoadingModal(false);
});
};