I'm using Reactjs
web application. There I'm calling Nodejs
RestAPI.
When API returns status code 400, I can't get it error message which is coming from API.
I'm not able to get the errorDesc
from API response.
400 error API response
{
"errorCode": "M400",
"message": "Invalid Request",
"errorDesc": "missing required first name field"
}
React code:
fetch(URL, {
method: 'POST',
body: data
})
.then(response => {
if (!response.ok) {
if (response.status == 400) {
Modal.error({
className: "ErrorModal",
title: "Error",
content: "Invalid Request.",
});
}
return Promise.reject(response.statusText);
}
return response.json();
})
.then(status => {
})
.catch(error => {
console.log(error);
});