From 3a88d983fc7fca513d0544daf1967356f2610739 Mon Sep 17 00:00:00 2001 From: dbroqua Date: Sat, 11 Jan 2020 21:56:55 +0100 Subject: [PATCH] Added try catch for getStream --- libs.js | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/libs.js b/libs.js index d75734e..2685aeb 100644 --- a/libs.js +++ b/libs.js @@ -173,23 +173,28 @@ const getStream = (callback) => { (error, response, body) => { if (!error && response.statusCode === 200) { let res = null - const _body = JSON.parse(body) + try { + const _body = JSON.parse(body) - res = { - artist: _body.data[0].track.artist, - title: _body.data[0].track.title, - album: _body.data[0].track.album, - royaltytrackid: _body.data[0].track.royaltytrackid, - id: _body.data[0].track.id, - stringId: _body.data[0].track.id || `FAKEID_${_body.data[0].track.artist}_${_body.data[0].track.title}_${_body.data[0].track.album}`, - playlistId: _body.data[0].track.playlist ? _body.data[0].track.playlist.id : null, - thumbCover: _body.data[0].track.imageurl - } + res = { + artist: _body.data[0].track.artist, + title: _body.data[0].track.title, + album: _body.data[0].track.album, + royaltytrackid: _body.data[0].track.royaltytrackid, + id: _body.data[0].track.id, + stringId: _body.data[0].track.id || `FAKEID_${_body.data[0].track.artist}_${_body.data[0].track.title}_${_body.data[0].track.album}`, + playlistId: _body.data[0].track.playlist ? _body.data[0].track.playlist.id : null, + thumbCover: _body.data[0].track.imageurl + } - if (res !== null && res.artist !== undefined && res.title !== undefined) { - callback(null, res) - } else { - error = true + if (res !== null && res.artist !== undefined && res.title !== undefined) { + callback(null, res) + } else { + error = true + } + } catch (e) { + error = e + console.error('getStream error:', error) } }