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", "name": "townsquare",
"version": "1.2.0", "version": "1.2.1",
"description": "Blood on the Clocktower Town Square", "description": "Blood on the Clocktower Town Square",
"author": "Steffen Baumgart", "author": "Steffen Baumgart",
"scripts": { "scripts": {

View File

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