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) => {
|
(error, response, body) => {
|
||||||
if (!error && response.statusCode === 200) {
|
if (!error && response.statusCode === 200) {
|
||||||
let res = null
|
let res = null
|
||||||
const _body = JSON.parse(body)
|
try {
|
||||||
|
const _body = JSON.parse(body)
|
||||||
|
|
||||||
res = {
|
res = {
|
||||||
artist: _body.data[0].track.artist,
|
artist: _body.data[0].track.artist,
|
||||||
title: _body.data[0].track.title,
|
title: _body.data[0].track.title,
|
||||||
album: _body.data[0].track.album,
|
album: _body.data[0].track.album,
|
||||||
royaltytrackid: _body.data[0].track.royaltytrackid,
|
royaltytrackid: _body.data[0].track.royaltytrackid,
|
||||||
id: _body.data[0].track.id,
|
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}`,
|
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,
|
playlistId: _body.data[0].track.playlist ? _body.data[0].track.playlist.id : null,
|
||||||
thumbCover: _body.data[0].track.imageurl
|
thumbCover: _body.data[0].track.imageurl
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res !== null && res.artist !== undefined && res.title !== undefined) {
|
if (res !== null && res.artist !== undefined && res.title !== undefined) {
|
||||||
callback(null, res)
|
callback(null, res)
|
||||||
} else {
|
} else {
|
||||||
error = true
|
error = true
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
error = e
|
||||||
|
console.error('getStream error:', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue