error system change

This commit is contained in:
Wise Colt
2019-01-01 01:24:58 +03:00
parent 604a237d08
commit a8f564adc0

View File

@@ -2,7 +2,7 @@
const cheerio = require('cheerio'); const cheerio = require('cheerio');
const request = require('request'); const request = require('request');
class RateFlix { class FlixInfo {
constructor(options = {}) { constructor(options = {}) {
if (!options.tmdbApiKey) throw new Error('Missing tmdb api key'); if (!options.tmdbApiKey) throw new Error('Missing tmdb api key');
@@ -24,9 +24,8 @@ class RateFlix {
request(flixableURL, (err, response, body) => { request(flixableURL, (err, response, body) => {
if (err) { if (err) {
const error = 'flixable.com request error details: ' + err; returnResult = { error: 0, errorMsg: 'flixable.com request error details: ' + err };
const returnResult = null; cb(returnResult)
cb(error, returnResult)
} }
else { else {
const $ = cheerio.load(body, { const $ = cheerio.load(body, {
@@ -45,9 +44,8 @@ class RateFlix {
request(tmdbURL, (err, resultBody, body) => { request(tmdbURL, (err, resultBody, body) => {
if (err) { if (err) {
const error = 'tmdb api request error details: ' + err; returnResult = { error: 0, errorMsg: 'tmdb api request error details: ' + err };
const returnResult = null; cb(returnResult)
cb(error, returnResult)
} }
else { else {
// Result convert the json // Result convert the json
@@ -59,10 +57,10 @@ class RateFlix {
var originalName = result.original_name; var originalName = result.original_name;
var name = result.name; var name = result.name;
var year = result.first_air_date; var year = result.first_air_date;
if(result.poster_path != null){ if (result.poster_path != null) {
var poster = 'https://image.tmdb.org/t/p/original/' + result.poster_path; var poster = 'https://image.tmdb.org/t/p/original/' + result.poster_path;
} }
if(result.poster_path != null){ if (result.poster_path != null) {
var backdrop = 'https://image.tmdb.org/t/p/original/' + result.backdrop_path; var backdrop = 'https://image.tmdb.org/t/p/original/' + result.backdrop_path;
} }
var country = result.origin_country[0]; var country = result.origin_country[0];
@@ -76,10 +74,10 @@ class RateFlix {
var originalName = result.original_title; var originalName = result.original_title;
var name = result.title; var name = result.title;
var year = result.release_date; var year = result.release_date;
if(result.poster_path != null){ if (result.poster_path != null) {
var poster = 'https://image.tmdb.org/t/p/original/' + result.poster_path; var poster = 'https://image.tmdb.org/t/p/original/' + result.poster_path;
} }
if(result.poster_path != null){ if (result.poster_path != null) {
var backdrop = 'https://image.tmdb.org/t/p/original/' + result.backdrop_path; var backdrop = 'https://image.tmdb.org/t/p/original/' + result.backdrop_path;
} }
var country = result.original_language; var country = result.original_language;
@@ -87,23 +85,20 @@ class RateFlix {
var overviewEN = result.overview; var overviewEN = result.overview;
} }
returnResult = { result: 1, originalName, name, year, poster, backdrop, country, rate, overviewEN }; returnResult = { result: 1, error: 0, originalName, name, year, poster, backdrop, country, rate, overviewEN };
const error = null;
// If there is no error return the result // If there is no error return the result
cb(error, returnResult); cb(returnResult);
} }
}); });
}) })
} }
else { else {
// Return the error if imdb id cannot be found // Return the error if imdb id cannot be found
const error = null const returnResult = { result: 0, error: 0 };
const returnResult = {result: 0}; cb(returnResult)
cb(error, returnResult)
} }
} }
}); });
} }
} }
module.exports = FlixInfo;
module.exports = RateFlix;