Skip to content

Commit

Permalink
fix(src): Fix reject errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lgaticaq committed Dec 18, 2016
1 parent 76e8579 commit 82a7258
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ const getLinksByUrl = uri => {
headers: {'User-Agent': userAgent}
};
cloudscraper.request(options, (err, response, body) => {
if (err) reject(err);
if (response.statusCode !== 200) reject(new Error(`Status code: ${response.statusCode}`));
if (err) return reject(err.error);
if (response.statusCode !== 200) return reject(new Error(`Status code: ${response.statusCode}`));
const $ = cheerio.load(body);
const validRegex = /http:\/\/jkanime\.net\/([\w\d-_]+)\/(\d+)/;
if (!validRegex.test(uri)) resolve(null);
const title = $('.vervideo').text().split(' - ')[0];
const _exec = validRegex.exec(uri).slice(1, 3);
const codeName = _exec[0];
Expand All @@ -41,8 +40,8 @@ const getLastChapter = name => {
headers: {'User-Agent': userAgent}
};
cloudscraper.request(options, (err, response, body) => {
if (err) reject(err);
if (response.statusCode !== 200) reject(new Error(`Status code: ${response.statusCode}`));
if (err) return reject(err.error);
if (response.statusCode !== 200) return reject(new Error(`Status code: ${response.statusCode}`));
const $ = cheerio.load(body);
const text = $('.listnavi a').last().text();
const result = parseInt(/\d+\s-\s(\d+)/.exec(text)[1], 10);
Expand All @@ -59,8 +58,8 @@ const searchAnime = keyword => {
headers: {'User-Agent': userAgent}
};
cloudscraper.request(options, (err, response, body) => {
if (err) reject(err);
if (response.statusCode !== 200) reject(new Error(`Status code: ${response.statusCode}`));
if (err) return reject(err.error);
if (response.statusCode !== 200) return reject(new Error(`Status code: ${response.statusCode}`));
const $ = cheerio.load(body);
const result = $('.listpage .titl').map(function() {
return {
Expand Down Expand Up @@ -91,6 +90,7 @@ const getName = keyword => {
return searchAnime(keyword).then(animes => {
if (animes.length === 0) throw new Error(`Not found anime with keyword "${keyword}"`);
const results = fuseSearch(animes, keyword);
if (results.length === 0) throw new Error('Not found');
return results[0].codeName;
});
};
Expand Down

0 comments on commit 82a7258

Please sign in to comment.