Permalink
Browse files

add try/catch in jango connector for JSON parsing on communication DIV

The change event was getting triggered when the div was still empty. The
empty string would get parsed as JSON and throw an exception.
  • Loading branch information...
1 parent b7b9968 commit 82447a8d50792e4eaf9db44ff96e81ba0552ccfb @shamer shamer committed May 29, 2012
Showing with 8 additions and 3 deletions.
  1. +8 −3 jango.js
View
@@ -6,17 +6,22 @@
// Used to cache the song title to prevent repeated calls to updateNowPlaying
var lastSongTitle = '';
-function updateNowPlaying(){
+function updateNowPlaying() {
var commDiv = document.getElementById('chromeLastFM');
- var songInfo = JSON.parse(commDiv.innerText);
+ try {
+ var songInfo = JSON.parse(commDiv.innerText);
+ } catch (e) {
+ // Skip malformed communication blobs
+ return;
+ }
if (songInfo['title'] == lastSongTitle) {
return;
}
lastSongTitle = songInfo['title'];
// Update scrobbler
- //console.log('submitting a now playing request. artist: ' + songInfo['artist'] + ', title: ' + songInfo['title'] + ', duration: ' + songInfo['duration']);
+ console.log('submitting a now playing request. artist: ' + songInfo['artist'] + ', title: ' + songInfo['title'] + ', duration: ' + songInfo['duration']);
chrome.extension.sendRequest({'type': 'validate', 'artist': songInfo['artist'], 'track': songInfo['title']}, function(response) {
if (response != false) {
chrome.extension.sendRequest({type: 'nowPlaying', 'artist': songInfo['artist'], 'track': songInfo['title'], 'duration': songInfo['duration']});

0 comments on commit 82447a8

Please sign in to comment.