How to break out of chain after a condition? I can't use try and catch because of the way I take the response(very bad response)
const fetchData = async dispatch => {
await axios
.get("/url.php?"})
.then(response => {
if (response.data.success === false) {
setFetchingOk(false);
logoutUser();
//Here i want that the chain(everything below) to stop totally
} else {
// bla bla bla
return response.headerFields
}
})
.then(headerFields =>
//bla bla bla
)
)
.then(response => {
});
};
Edit: I solved it by throwing an error at my condition block like
throw new Error("Not authorized");
and then at the end of the chain adding
.catch(function(error) {
console.log(error);
});
Now it doesn't give Fatal Error