Added try catch for getStream
This commit is contained in:
parent
63ab17ce4c
commit
3a88d983fc
1 changed files with 20 additions and 15 deletions
35
libs.js
35
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue