Display error message from JSON to end user
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user