Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle error when host does not respond? #76

Open
tomsoderlund opened this issue Jun 20, 2018 · 1 comment
Open

How to handle error when host does not respond? #76

tomsoderlund opened this issue Jun 20, 2018 · 1 comment

Comments

@tomsoderlund
Copy link

tomsoderlund commented Jun 20, 2018

I'm using html-metadata to parse a list of hostnames:

const htmlMetadata = require('html-metadata');

console.log(`Domain: ${domain}`);
const newUrl = completeUrl(domain);
htmlMetadata(newUrl, (err, data) => {
	console.log(`htmlMetadata callback:`, err);
	const newData = {
		url: newUrl,
		shortName: _.capitalize(newUrl.split('.')[1]),
		tld: newUrl.split('.').pop(),
		title: _.get(data, 'general.title', '').replace(ALL_LINEBREAKS, '').replace(ALL_TABS, ''),
		description: _.get(data, 'general.description', '').replace(ALL_LINEBREAKS, '').replace(ALL_TABS, ''),
	}
	cb(null, newData); // even if err, don't propagate it
});

However, when host does not respond, I get this error:

Domain: f-edition.se
_http_agent.js:186
        nextTick(newSocket._handle.getAsyncId(), function() {
                          ^

TypeError: Cannot read property '_handle' of undefined
    at _http_agent.js:186:27
    at Timeout._onTimeout (/Users/tomsoderlund/Documents/Projects/Weld.io/Development/weld-extensions/cabal/node_modules/preq/index.js:24:17)
    at ontimeout (timers.js:488:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:283:5)

Please note that this happens before my htmlMetadata callback is triggered.

I've tried wrapping my code in try/catch but it doesn't help, I guess it's because it's async and the error is happening in a different thread.

Any tips?

@mvolz
Copy link
Collaborator

mvolz commented Aug 5, 2018

Hmm, unfortunately I haven't used the callback version of these methods at all; they're all bluebird Promises and wrapped using Promise.nodeify() and we just use the native Promise version. See: http://bluebirdjs.com/docs/api/ascallback.html - maybe that documentation about how to handle errors will be helpful? I do know that a lot of times "promisify" or "nodeify" methods don't always work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants