Display error message from JSON to end user

This commit is contained in:
2025-01-17 17:26:24 +01:00
parent f94e08fc7f
commit fde07b74fa

View File

@ -108,12 +108,14 @@
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
if (!response.ok) throw new Error("Failed to submit vote.");
if (!response.ok) {
res = await response.json();
throw new Error(res.message);
}
this.message = "Vote submitted successfully!";
this.success = true;
} catch (error) {
console.error(error);
this.message = "Failed to submit vote.";
this.message = error.message;
this.success = false;
}
}