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