Display error message from JSON to end user
This commit is contained in:
@ -108,12 +108,14 @@
|
|||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify(payload),
|
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.message = "Vote submitted successfully!";
|
||||||
this.success = true;
|
this.success = true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
this.message = error.message;
|
||||||
this.message = "Failed to submit vote.";
|
|
||||||
this.success = false;
|
this.success = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user