Skip to content

Commit

Permalink
Add alert if JSON is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyBF committed Nov 26, 2023
1 parent 8075e0a commit c34f1e9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions web_ext/sseq_gui/interface/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,19 @@ messageHandler.Error = m => {
document.getElementById('json-upload').addEventListener('change', () => {
const file = document.getElementById('json-upload').files[0];
const fileReader = new FileReader();

fileReader.onload = e => {
// Remove whitespace to shorten URL
const json = JSON.stringify(JSON.parse(e.target.result));
window.location = `?module_json=${encodeURIComponent(json)}`;
try {
// Attempt to parse JSON
const json = JSON.stringify(JSON.parse(e.target.result));
window.location = `?module_json=${encodeURIComponent(json)}`;
} catch (error) {
// If an error occurs, display an error message
alert('Invalid JSON file. Please upload a valid JSON file.');
console.error('Error parsing JSON:', error);
}
};

fileReader.readAsText(file, 'UTF-8');
});

Expand Down

0 comments on commit c34f1e9

Please sign in to comment.