From 9d3aefbe1b623871e562a4495869e13cba197a46 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 17 Apr 2016 18:11:05 +0200 Subject: [PATCH] Better errors --- public/index.html | 9 +++++++++ public/script.js | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/public/index.html b/public/index.html index e9dbe1e..d93ebb0 100644 --- a/public/index.html +++ b/public/index.html @@ -9,6 +9,7 @@
+

This is an example of the Authorization Code flow

Log in with Spotify @@ -61,8 +62,16 @@ {{/list}} + + + diff --git a/public/script.js b/public/script.js index 3072b40..a3792ef 100644 --- a/public/script.js +++ b/public/script.js @@ -3,6 +3,23 @@ var access_token; var refresh_token; var error; + +var userProfileSource = document.getElementById('user-profile-template').innerHTML, + userProfileTemplate = Handlebars.compile(userProfileSource), + userProfilePlaceholder = document.getElementById('user-profile'); + +var playlistsSource = document.getElementById('playlists-template').innerHTML, + playlistsTemplate = Handlebars.compile(playlistsSource), + playlistsPlaceholder = document.getElementById('playlists'); + +var dupsSource = document.getElementById('dups-template').innerHTML, + dupsTemplate = Handlebars.compile(dupsSource), + dupsPlaceholder = document.getElementById('dups'); + +var errorSource = document.getElementById('error-template').innerHTML, + errorTemplate = Handlebars.compile(errorSource), + errorPlaceholder = document.getElementById('error'); + (function () { /** @@ -29,18 +46,6 @@ var error; return out + "
"; }); - var userProfileSource = document.getElementById('user-profile-template').innerHTML, - userProfileTemplate = Handlebars.compile(userProfileSource), - userProfilePlaceholder = document.getElementById('user-profile'); - - var playlistsSource = document.getElementById('playlists-template').innerHTML, - playlistsTemplate = Handlebars.compile(playlistsSource), - playlistsPlaceholder = document.getElementById('playlists'); - - var dupsSource = document.getElementById('dups-template').innerHTML, - dupsTemplate = Handlebars.compile(dupsSource), - dupsPlaceholder = document.getElementById('dups'); - var params = getHashParams(); access_token = params.access_token; @@ -48,7 +53,11 @@ var error; error = params.error; if (error) { - alert('There was an error during the authentication'); + + errorPlaceholder.innerHTML = errorTemplate({ + err_title: 'Error!', + err_content: 'There was an error during the authentication. Feel free to open an issue.' + }); } else { if (access_token) { getPersonnalInfo(true, userProfilePlaceholder, userProfileTemplate); @@ -160,7 +169,10 @@ function getPersonnalInfo(first, userProfilePlaceholder, userProfileTemplate) { getPersonnalInfo(false, userProfilePlaceholder, userProfileTemplate); } else { - alert("Error getting personnal info"); + errorPlaceholder.innerHTML = errorTemplate({ + err_title: 'Error!', + err_content: 'Error while refreshing token. Please return to login.' + }); } } }