mirror of
https://github.com/Garmelon/Arbeitszeitdokumentationsgenerator.git
synced 2026-04-13 01:05:04 +02:00
Catch JSON parse errors
This commit is contained in:
parent
dbde9288cf
commit
e5ca4974d0
2 changed files with 22 additions and 8 deletions
|
|
@ -24,11 +24,11 @@ function showError(msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
submit.addEventListener("click", async () => {
|
submit.addEventListener("click", async () => {
|
||||||
|
showStatus("Generiere...");
|
||||||
|
|
||||||
const data = new FormData(form);
|
const data = new FormData(form);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
showStatus("Generiere...");
|
|
||||||
|
|
||||||
const response = await fetch(".", {
|
const response = await fetch(".", {
|
||||||
method: "post",
|
method: "post",
|
||||||
body: new URLSearchParams(data),
|
body: new URLSearchParams(data),
|
||||||
|
|
|
||||||
|
|
@ -24,15 +24,29 @@ function showError(msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
submit.addEventListener("click", async () => {
|
submit.addEventListener("click", async () => {
|
||||||
const data = new FormData(form);
|
|
||||||
const dataJson = JSON.stringify({
|
|
||||||
global: JSON.parse(data.get("global")),
|
|
||||||
month: JSON.parse(data.get("month")),
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
showStatus("Generiere...");
|
showStatus("Generiere...");
|
||||||
|
|
||||||
|
const data = new FormData(form);
|
||||||
|
|
||||||
|
let global;
|
||||||
|
try {
|
||||||
|
global = JSON.parse(data.get("global"));
|
||||||
|
} catch (e) {
|
||||||
|
showError(`Generieren fehlgeschlagen:\nFailed to read Global.json:\n${e}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let month;
|
||||||
|
try {
|
||||||
|
month = JSON.parse(data.get("month"));
|
||||||
|
} catch (e) {
|
||||||
|
showError(`Generieren fehlgeschlagen:\nFailed to read Month.json:\n${e}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dataJson = JSON.stringify({ global, month });
|
||||||
|
|
||||||
|
try {
|
||||||
const response = await fetch(".", {
|
const response = await fetch(".", {
|
||||||
method: "post",
|
method: "post",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue