Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Gracefully handle webpages that cannot be parsed with jsdom/jQuery #42

Merged
merged 1 commit into from

2 participants

John Hurliman Chris O'Hara
John Hurliman

This adds a try/catch block around the initialization of jsdom/jQuery for a fetched webpage and returns the exception (if any) as the callback err parameter instead of crashing the node.io process.

Chris O'Hara
Owner

Perfect, thanks

Chris O'Hara chriso merged commit b26a86c into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 5 deletions.
  1. +11 −5 lib/node.io/dom.js
16 lib/node.io/dom.js
View
@@ -50,12 +50,18 @@ Job.prototype.parseHtml = function (data, callback, response) {
ProcessExternalResources: this.options.external_resources,
QuerySelector: false
};
- var $, window = require('jsdom').jsdom(data, null, {features:features}).createWindow(),
- jquery = require('jquery')
+ var $, window, jquery, default_$;
+ try {
+ window = require('jsdom').jsdom(data, null, {features:features}).createWindow();
+ jquery = require('jquery');
default_$ = jquery.create(window);
- $ = function (selector, context) {
- return context ? jquery.create(context)(selector) : default_$(selector);
- };
+ $ = function (selector, context) {
+ return context ? jquery.create(context)(selector) : default_$(selector);
+ };
+ } catch (e) {
+ callback.apply(self, [e, $, data, headers, response]);
+ return;
+ }
if (recurse === 1 || recurse === true || recurse instanceof Array) {
this.recurseUrls($);
}
Something went wrong with that request. Please try again.