ruipgil / scraperjs

A complete and versatile web scraper.
MIT License
3.7k stars 188 forks source link

.catch() function doesn't exist #51

Closed v1p closed 8 years ago

v1p commented 8 years ago

I am trying to run the following code :

scraperjs.StaticScraper
        .create({
            url: url,
            headers: {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36'}
        })
        .scrape(function ($) {

            // REDACTED

        }, function (data) {
            console.log(data);
        })
        .catch(function(err, utils){
            switch (err.code) {
                case 'ENOTFOUND':
                    debug("Page '%s' not found", err.hostname);
                    break;
                case '30THLINK':
                    debug("Page '%s' doesn't have a 30th link", utils.url);
                    break;
                default:
                    debug('Unknown error found %s', err);
            }
        });

And I am getting this error :

[TypeError: Object [object Object] has no method 'catch']

Without this .catch(), I am not able to catch 'ENOTFOUND' errors.

I saw the Error Handling example, where the .catch() is used but with 'router' (which returns a scraper promise as well). I am not sure if I am following the guide correctly based on the available promise list on the scraper object mentioned in README.

Any pointers that if I am missing something ? (I tried placing .catch() before .scrape() as well)

ruipgil commented 8 years ago

Just to make sure, what version of scraperjs are you running?

The onError promise is deprecated for catch since v1.0.0.

v1p commented 8 years ago

@ruipgil : My Bad, I was on pre 1.0.0 version, just upgraded it & the .catch() is working fine now. Thanks for prompt reply :) !