better error handling

This commit is contained in:
AJ ONeal 2018-07-08 02:57:33 +00:00
parent 5aed381963
commit 79e9728d19
2 changed files with 10 additions and 3 deletions

View File

@ -9,7 +9,7 @@
<div class="js-error" hidden> <div class="js-error" hidden>
<h1>Invalid Magic Link</h1> <h1>Invalid Magic Link</h1>
<div class="js-magic-link">'{{magic_link}}' isn't a valid magic link code. <div class="js-magic-link">'{{magic_link}}' isn't a valid magic link code.
<br>Links are only good for 5 minutes, so you gotta act fast. <br>Links are only valid for a limited time, so you gotta act fast.
</div> </div>
</div> </div>

View File

@ -53,11 +53,17 @@ function submitCode(pair) {
// shouldn't be pending (because we get here by being ready) // shouldn't be pending (because we get here by being ready)
// should poll over 'ready' // should poll over 'ready'
console.log('Submit Code Response:');
console.log(data);
if (data.error) {
document.querySelector('.js-error').hidden = false;
return;
}
setTimeout(checkStatus, 0); setTimeout(checkStatus, 0);
document.querySelector('.js-authz').hidden = false; document.querySelector('.js-authz').hidden = false;
console.log(data);
/* /*
document.querySelectorAll('.js-token-data').forEach(function ($el) { document.querySelectorAll('.js-token-data').forEach(function ($el) {
$el.innerText = JSON.stringify(data, null, 2); $el.innerText = JSON.stringify(data, null, 2);
@ -90,6 +96,7 @@ function init() {
if (!magic) { if (!magic) {
document.querySelector('body').hidden = false; document.querySelector('body').hidden = false;
document.querySelector('.js-error').hidden = false; document.querySelector('.js-error').hidden = false;
return;
} }
window.fetch(meta.baseUrl + meta.pair_request.pathname + '/' + magic, { window.fetch(meta.baseUrl + meta.pair_request.pathname + '/' + magic, {
@ -97,7 +104,7 @@ function init() {
, cors: true , cors: true
}).then(function (resp) { }).then(function (resp) {
return resp.json().then(function (data) { return resp.json().then(function (data) {
console.log('Data:'); console.log('pair request:');
console.log(data); console.log(data);
document.querySelector('body').hidden = false; document.querySelector('body').hidden = false;
if (data.error) { if (data.error) {