Michael Sterling
asked on
In react, what is the correct syntax in a fetch call to catch a 404 error?
I'm having trouble with finding the correct syntax to catcha 404 error from my api call. Currently if there is a 404 it never appears to make it to the:
part of the call. I'm currently searching for an example but can't seem to find a simplified one.
fetch snippet
.catch(() => this.setState({ hasErrors: true }))
part of the call. I'm currently searching for an example but can't seem to find a simplified one.
fetch snippet
fetch('http://localhost/MICROSERVICES/TestAPI1/api/Users/test/' + mid)
.then(res => res.json())
.then((res) => {
setUserInfo({userInfo: res});
})
.catch(() => this.setState({ hasErrors: true }))
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.