Skip to content

Commit 740ca91

Browse files
author
oleg.kulyk
committed
Additional checks
1 parent e3bdfcd commit 740ca91

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

products-scraper.js

+22-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ class ProductsScraper {
2323

2424
async startScraping() {
2525
this.checkForCountry();
26-
27-
if (this.numberOfProducts > CONSTANTS.limit.product) {
28-
this.numberOfProducts = CONSTANTS.limit.product;
29-
console.info(`Setting number to MAXIMUM available (${CONSTANTS.limit.product}) because of exceeding limit`);
30-
}
26+
this.checkForApiKey();
27+
this.checkForKeyword();
28+
this.checkForProductsNumber();
3129

3230
while (true) {
3331
if (this.alreadyScrappedProducts.length >= this.numberOfProducts) {
@@ -80,6 +78,25 @@ class ProductsScraper {
8078
}
8179
}
8280

81+
checkForApiKey() {
82+
if (!this.apiKey) {
83+
throw `No RapidAPI apiKey. Please refer to https://rapidapi.com/okami4kak/api/scrapingant for getting yours.`;
84+
}
85+
}
86+
87+
checkForKeyword() {
88+
if (!this.keyword) {
89+
throw `No keyword for search. Please specify it..`;
90+
}
91+
}
92+
93+
checkForProductsNumber() {
94+
if (this.numberOfProducts > CONSTANTS.limit.product) {
95+
this.numberOfProducts = CONSTANTS.limit.product;
96+
console.info(`Setting number to MAXIMUM available (${CONSTANTS.limit.product}) because of exceeding limit.`);
97+
}
98+
}
99+
83100
async getCurrentPageData() {
84101
const queryParams = querystring.encode({
85102
k: this.keyword,

0 commit comments

Comments
 (0)