我正在使用ReactJS进行PUT请求,但是当我输入错误的电子邮件/密码组合时,即使我试图捕获所有错误并在
errorDiv
中显示它们,Chrome也会记录下这些错误。
async connect(event) {
try {
const userObject = {
username: this.state.userName,
password: this.state.password
};
if (!userObject.username || !userObject.password) {
throw Error('The username/password is empty.');
}
let response = await fetch(('someurl.com'), {
method: "PUT",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(userObject)
});
let resJSON = await response.json();
if (!response.ok) {
throw Error(resJSON.message);
}
console.info(resJSON.message);
console.info(resJSON.message.auth_token);
window.location = "/ledger/home";
} catch (e) {
document.getElementById("errorDiv").style.display = 'block';
document.getElementById("errorDiv").innerHTML = e;
}
}