add error message when provided JSON is invalid

This commit is contained in:
Steffen 2020-07-01 10:31:02 +02:00
parent b158230fce
commit 300066a551
No known key found for this signature in database
GPG Key ID: 764D74E98267DFC6
2 changed files with 14 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{
"name": "townsquare",
"version": "1.2.0",
"version": "1.2.1",
"description": "Blood on the Clocktower Town Square",
"author": "Steffen Baumgart",
"scripts": {

View File

@ -116,7 +116,13 @@ export default {
if (file && file.size) {
const reader = new FileReader();
reader.addEventListener("load", () => {
this.parseRoles(JSON.parse(reader.result));
try {
const roles = JSON.parse(reader.result);
this.parseRoles(roles);
} catch (e) {
alert("Error reading custom script: " + e.message);
}
this.$refs.upload.value = "";
});
reader.readAsText(file);
}
@ -130,8 +136,12 @@ export default {
async handleURL(url) {
const res = await fetch(url);
if (res && res.json) {
try {
const script = await res.json();
this.parseRoles(script);
} catch (e) {
alert("Error loading custom script: " + e.message);
}
}
},
parseRoles(roles) {