Fixed bug on json parse

This commit is contained in:
dbroqua 2020-01-16 10:11:02 +01:00
parent b6beab9a71
commit d2ebf282aa

View file

@ -99,6 +99,7 @@ if (!process.env.STREAM_TYPE || process.env.STREAM_TYPE === 'radio') {
}, },
(error, response, body) => { (error, response, body) => {
if (!error && response.statusCode === 200) { if (!error && response.statusCode === 200) {
try {
const res = JSON.parse(process.env.STREAM_PARSE ? body.replace('updateFromMediaItem(', '').replace(');', '') : body) const res = JSON.parse(process.env.STREAM_PARSE ? body.replace('updateFromMediaItem(', '').replace(');', '') : body)
let title = null let title = null
@ -140,6 +141,10 @@ if (!process.env.STREAM_TYPE || process.env.STREAM_TYPE === 'radio') {
if (previousSong.title !== currentSong.title && previousSong.artist !== currentSong.artist) { if (previousSong.title !== currentSong.title && previousSong.artist !== currentSong.artist) {
checkCurrentSong() checkCurrentSong()
} }
} catch (e) {
error = e
console.error('getStream error:', error)
}
} else { } else {
console.error('ERR:', error) console.error('ERR:', error)
} }