I'm using Cross fetch for my ReactJS API calls
Is there a way to capture 400 401 & 403 in fetch response.
Here is sample code of using fetch
fetch('https://jsonplaceholder.typicode.com/posts', {
method: 'POST',
body: JSON.stringify({
title: 'foo',
body: 'bar',
userId: 1
}),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(response => response.json())
.then(json => console.log(json))
then:.then(response => { if(response.status===400) { console.log('status 400'); } return response.json() }