Better errors

This commit is contained in:
Gabriel Augendre 2016-04-17 18:11:05 +02:00
parent 0c42e0b9b3
commit 9d3aefbe1b
2 changed files with 35 additions and 14 deletions

View file

@ -9,6 +9,7 @@
<body>
<div class="container">
<div id="error"></div>
<div id="login">
<h1>This is an example of the Authorization Code flow</h1>
<a href="/login" class="btn btn-primary">Log in with Spotify</a>
@ -61,8 +62,16 @@
{{/list}}
</script>
<script id="error-template" type="text/x-handlebars-template">
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<strong>{{err_title}}</strong> {{{err_content}}}.
</div>
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0-alpha.1/handlebars.min.js"></script>
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="./script.js"></script>
</body>
</html>

View file

@ -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 + "</div>";
});
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 <a href="https://github.com/Crocmagnon/Spotify-Duplicate-Finder/issues" class="alert-link">open an issue</a>.'
});
} 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 <a href="/" class="alert-link">return to login</a>.'
});
}
}
}