Skip to content

Commit

Permalink
feat: add error handling to try it life!
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjoDiaz committed Aug 23, 2022
1 parent ef2efd3 commit 950c4e8
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
.panel-heading, .panel-tabs {
margin: 0 !important;
}

.alert {
position: fixed;
bottom: 3rem;
right: 2rem;
max-width: 30rem;
}
</style>
</head>
<body>
Expand Down Expand Up @@ -114,18 +121,29 @@
},
methods: {
formatJSON() {
try {
this.inputJSON = JSON.stringify(JSON.parse(this.inputJSON), null, 4);
// TODO error
} catch (err) {
this.showError(err);
}
},
parseJSON() {
const parser = new Json2csvStreamParser(this.configJSON);
this.outputCSV = '';
parser.onData = data => {
this.outputCSV += data;
};
parser.onError = console.error; // TODO
parser.onError = this.showError;
parser.write(this.inputJSON);
parser.end();
},
showError(err) {
const notification = document.createElement ('div');
notification.classList.add('notification', 'is-danger', 'alert');
notification.innerText = err.message;
notification.addEventListener('click', () => document.body.removeChild(notification));
document.body.appendChild(notification);
setTimeout(() => notification.dispatchEvent('click'), 2000);
}
}
},
Expand Down

0 comments on commit 950c4e8

Please sign in to comment.