From 83f89695c9e96b5194c1a2d1b9558c7aac12edc9 Mon Sep 17 00:00:00 2001 From: Wise Colt Date: Tue, 31 Mar 2020 02:05:55 +0300 Subject: [PATCH] bu fixes --- example/getinfo.js | 3 ++- lib/module.js | 38 +++++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/example/getinfo.js b/example/getinfo.js index dc71ef3..7ac0c54 100644 --- a/example/getinfo.js +++ b/example/getinfo.js @@ -3,7 +3,8 @@ const GetFlix = require('../index'); const getflix = new GetFlix('d9d6007d1bcf12043db5a085ae3e5bbb'); const getInfo = async () => { try { - const info = await getflix.get(80209184, 'tr-TR'); + const info = await getflix.get(80244780, 'tr-TR'); + // info.credits.cast.forEach((f) => console.log(f.profile_path)); console.log(info); } catch (error) { diff --git a/lib/module.js b/lib/module.js index 4b4b890..4c59b16 100644 --- a/lib/module.js +++ b/lib/module.js @@ -6,31 +6,35 @@ module.exports.getDetails = function (detailsId, movieOrTv, tmdbApiKey, language if (movieOrTv == 'movie' || movieOrTv == 'tv') { const detailURL = config.theMovieDbURL + movieOrTv + '/' + detailsId + '?api_key=' + tmdbApiKey + '&language=' + language; - + request(detailURL, (err, resultBody, body) => { + if (resultBody != '') { + const getJson = JSON.parse(resultBody.body); - const getJson = JSON.parse(resultBody.body); - - if (getJson.status_code > 1) { - // if wrong api key error - const error = 'tmdb get detail wrong api key error'; - const result = null; - cb(error, result); - } - else { - if (err) { - // if thmdb api connection error - const error = 'tmdb get detail api connection error'; + if (getJson.status_code > 1) { + // if wrong api key error + const error = 'tmdb get detail 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 detail api connection error'; + const result = null; + cb(error, result); + } + else { + const error = null; + const result = getJson; + cb(error, result); + } } + } else { + const error = 'tmdb get detail api connection error'; + const result = null; + cb(error, result); } - }); } else {