From 5b0f06e6eea66cab1a0b92599a2240795d23b4a3 Mon Sep 17 00:00:00 2001 From: Wise Colt Date: Fri, 24 Apr 2020 00:12:43 +0300 Subject: [PATCH] bug fix --- lib/module.js | 43 ++++++++++++++++++++++++------------------- package.json | 2 +- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/lib/module.js b/lib/module.js index d0ef2f6..489599a 100644 --- a/lib/module.js +++ b/lib/module.js @@ -5,8 +5,8 @@ module.exports.getDetails = function (detailsId, movieOrTv, tmdbApiKey, language if (movieOrTv == 'movie' || movieOrTv == 'tv') { - const detailURL = config.theMovieDbURL + movieOrTv + '/' + detailsId + '?api_key=' + tmdbApiKey + '&language=' + language; - + const detailURL = config.theMovieDbURL + movieOrTv + '/' + detailsId + '?api_key=' + tmdbApiKey + '&language=' + language; + request(detailURL, (err, resultBody, body) => { if (resultBody != '') { const getJson = JSON.parse(resultBody.body); @@ -110,7 +110,7 @@ module.exports.getTrailers = function (detailsId, movieOrTv, tmdbApiKey, cb) { else { const error = null; const result = getJson; - + cb(error, result); } } @@ -132,28 +132,33 @@ module.exports.getImages = function (detailsId, movieOrTv, tmdbApiKey, cb) { request(creditsURL, (err, resultBody, body) => { - const getJson = JSON.parse(resultBody.body); - - if (getJson.status_code > 1) { - // if wrong api key error - const error = 'tmdb get images wrong api key error'; - const result = null; - cb(error, result); - } - else { - if (err) { - // if thmdb api connection error - const error = 'tmdb get images api connection error'; + if (resultBody != []) { + const getJson = JSON.parse(resultBody.body); + if (getJson.status_code > 1) { + // if wrong api key error + const error = 'tmdb get images wrong api key error'; const result = null; cb(error, result); } else { - const error = null; - const result = getJson; - cb(error, result); + if (err) { + // if thmdb api connection error + const error = 'tmdb get images api connection error'; + const result = null; + cb(error, result); + } + else { + const error = null; + const result = getJson; + cb(error, result); + } } + } else { + // if wrong api key error + const error = 'error getting data'; + const result = null; + cb(error, result); } - }); } else { diff --git a/package.json b/package.json index d9728a8..634dbe1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "flixinfo", - "version": "1.1.8", + "version": "1.1.9", "description": "Get movie detail with netflix id", "main": "index.js", "directories": {