This repository was archived by the owner on Nov 15, 2022. It is now read-only.

Description
I have a button which on click uses axios to save the form data. I have that in a try catch. The axios request works just fine, but when I try to navigate to a new "page", an error is thrown. When I catch and log the error it just shows: wth !
const SaveEvent = async () => {
let savedOk = false
setSaving(true)
const data = {
...
}
try {
const result = await axios({
method: 'post',
url: 'http://localhost:49505/principal/api/AddEvent',
headers : {'content-type' : 'application/json'},
data: JSON.stringify(data)
})
if (result.data === "ok") {
alert("Evening Saved")
savedOk = true
navigate('/admin/events', true);
}
} catch (e) {
console.log(e);
alert("Error Saving Data")
} finally {
if (!savedOk) setSaving(false)
};
}
...
<button className="btn right waves-effect waves-light" id="btnAddEventSave" onClick={SaveEvent}><i className="material-icons left">save</i> SAVE</button>
...
{saving &&
<div className="progress">
<div className="indeterminate"></div>
</div>
}
if I move the navigate out of the try/catch, I get an error in the console saying uncaught error...
The navigation works ok, but I don't want to have to check for a wth error in my catch. What am I doing wrong>