axios.get('/api/xyz/abcd')
.catch(function (error) {
if (error.response) {
// Request made and server responded
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else if (error.request) {
// The request was made but no response was received
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
}
});
axios.get('/api/xyz/abcd')
.catch(function (error) {
if (error.response) {
// Request made and server responded
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else if (error.request) {
// The request was made but no response was received
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
}
});
const onSubmit = async (FormData) => {
FormData.bFlats = meters;
try {
let res = await axios({
method: 'post',
url: 'http://localhost:5000/api/v1/buildings',
data: FormData
});
console.log(res.data);
if (res.data.status === 'success') {
alert("Successfully Inserted");
reset();
}
} catch (error) {
console.log(error.response.data.message); // this is the main part. Use the response property from the error object
}
}
// WHEN WORKING WITH LOCALHOST
/* The thing is, that iOS is running in a simulator and Android is running in an emulator.
The localhost is pointing to the environment in which the code is running.
The emulator emulates a real device while the simulator is only imitating the device.
Therefore the localhost on Android is pointing to the emulated Android device.
And not to the machine on which your server is running.
The solution is to replace localhost with the IP address of your machine. */