Skip to content

Instantly share code, notes, and snippets.

@fgandellini
Last active August 29, 2015 14:25
Show Gist options
  • Save fgandellini/4b868198b6cedf4d51eb to your computer and use it in GitHub Desktop.
Save fgandellini/4b868198b6cedf4d51eb to your computer and use it in GitHub Desktop.
check link
function check(link) {
var errorMessage = 'Mumble mumble... this seems to be an invalid link! :(';
return new Promise(function(resolve, reject) {
try {
http.request(link, function(res) {
debug('link status is ', res.statusCode);
if (res.statusCode !== 404) {
resolve(link);
} else {
reject(errorMessage);
}
}).end();
} catch(ex) {
reject(errorMessage);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment