I'm trying to check whether my request was sucessecul or not so i had to add an If condition. So, if the condition is true (bad request) i should stop the function and not run the command that come after my condition. My code looks like this:
async function updateUserInfo(userData) {
const modal = document.querySelector('.userInfos > dialog')
//modal.close()
const userToken = getUserToken()
const nuUserSettings = await fetch(`http://localhost:6278/users`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${userToken}`,
},
body: JSON.stringify(userData)
})
.then(res => {
if (res.status === 400) {
return
}
})
console.log('return didnt work function is still running')
.then(res => res.json())
}
i tried placing all the leftover code in a 'else' condition but it didn't work out cause .then(res => res.json()) was simply not working