I am facing a situation where the route of my fetch()
call can result in two different responses, each requiring a different action. However, I have noticed that the catch()
method only handles network errors as far as I know.
Currently, my code looks like below, but I can't help but feel that there might be a more efficient way to handle this scenario. Is there a better approach?
fetch(`${this.baseUrl}/wp-json/contact/v1/send`, {
method: 'POST',
body: formData
})
.then((res) => {
if (res.status === 304) {
// perform specific action
} else {
// perform another action
}
})
.catch(error => {
console.log(error)
})