mirror of
https://github.com/Garmelon/Arbeitszeitdokumentationsgenerator.git
synced 2026-04-12 08:45:05 +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 () => {
|
||||
showStatus("Generiere...");
|
||||
|
||||
const data = new FormData(form);
|
||||
|
||||
try {
|
||||
showStatus("Generiere...");
|
||||
|
||||
const response = await fetch(".", {
|
||||
method: "post",
|
||||
body: new URLSearchParams(data),
|
||||
|
|
|
|||
|
|
@ -24,15 +24,29 @@ function showError(msg) {
|
|||
}
|
||||
|
||||
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...");
|
||||
|
||||
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(".", {
|
||||
method: "post",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue