I am doing POST request with invalid data, I do it on purpose, because I am testing response messages from server. When I pass valid data, then everything is ok. Server is built on express.js
Here is my frontend code with axios:
async function submitRegister() {
try {
const responseFromServer = await axios.post('http://localhost:5000/register', {
value1: value1,
value2: value2,
value3: value3,
value4: value4,
value5: value5
}, {
headers: {
'Content-Type': 'application/json'
},
withCredentials: true
});
if (responseFromServer.status === 201) {
console.log(responseFromServer);
} else {
console.log(responseFromServer);
}
} catch (error) {
console.log(error);
}
}
When status 400 I want get that json response:
if (validationMessage) {
return res.status(400).json({
success: false,
message: validationMessage,
isLoggedIn: req.session.isLoggedIn
});
}
But instead I see in console: POST http://localhost:5000/register 400 (Bad Request) Error: Request failed with status code 400