Handle NetworkErrors when submitting
This commit is contained in:
parent
40f4520458
commit
3dce933721
24
src/App.tsx
24
src/App.tsx
|
@ -33,7 +33,7 @@ function App() {
|
|||
}
|
||||
|
||||
const showThenHide = async () => {
|
||||
const response = await fetch("http://localhost:8080/post", {
|
||||
await fetch("http://localhost:8080/post", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
rating: rating,
|
||||
|
@ -41,19 +41,23 @@ function App() {
|
|||
title: fields[1].dynamicState[0],
|
||||
content: fields[2].dynamicState[0]
|
||||
})
|
||||
}).then((response) => response.json());
|
||||
})
|
||||
.then(async ({ json }) => {
|
||||
const result = await json();
|
||||
|
||||
response.error ? changeAlertText(`${response.error.type}: ${response.error.message}`) : changeAlertText(`Success: ${response.message}`);
|
||||
changeAlertText(result.error ? `${result.error.type}: ${result.error.message}` : `Success: ${result.message}`);
|
||||
})
|
||||
.catch((err) => changeAlertText(err.toString()));
|
||||
|
||||
if (showAlert) {
|
||||
return;
|
||||
}
|
||||
if (showAlert) {
|
||||
return;
|
||||
}
|
||||
|
||||
changeAlert(true);
|
||||
changeAlert(true);
|
||||
|
||||
setTimeout(() => {
|
||||
changeAlert(false);
|
||||
}, 3000);
|
||||
setTimeout(() => {
|
||||
changeAlert(false);
|
||||
}, 2500);
|
||||
}
|
||||
|
||||
const buttons: ActionProps[] = [
|
||||
|
|
Loading…
Reference in a new issue