My goal was to check the success of my request by adding an If condition. If the condition turns out to be true (indicating a bad request), I needed to stop the function and prevent the execution of subsequent commands. Here is an overview of my code:
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 didn't work function is still running')
.then(res => res.json())
}
I attempted to move the remaining code into an 'else' condition, but it did not work as expected because the operation of '.then(res => res.json())' was not functioning properly.