Handle NetworkErrors when submitting
This commit is contained in:
parent
40f4520458
commit
3dce933721
12
src/App.tsx
12
src/App.tsx
|
@ -33,7 +33,7 @@ function App() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const showThenHide = async () => {
|
const showThenHide = async () => {
|
||||||
const response = await fetch("http://localhost:8080/post", {
|
await fetch("http://localhost:8080/post", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
rating: rating,
|
rating: rating,
|
||||||
|
@ -41,9 +41,13 @@ function App() {
|
||||||
title: fields[1].dynamicState[0],
|
title: fields[1].dynamicState[0],
|
||||||
content: fields[2].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) {
|
if (showAlert) {
|
||||||
return;
|
return;
|
||||||
|
@ -53,7 +57,7 @@ function App() {
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
changeAlert(false);
|
changeAlert(false);
|
||||||
}, 3000);
|
}, 2500);
|
||||||
}
|
}
|
||||||
|
|
||||||
const buttons: ActionProps[] = [
|
const buttons: ActionProps[] = [
|
||||||
|
|
Loading…
Reference in a new issue