From eb7a9583529c259f2362873305e89d7a1ba992ff Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Wed, 30 Jan 2013 09:56:56 +0100 Subject: [PATCH] Don't pork up if UD is down --- modules/link/link.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/link/link.js b/modules/link/link.js index 201d364..d684cf3 100644 --- a/modules/link/link.js +++ b/modules/link/link.js @@ -52,15 +52,17 @@ var link = function(dbot) { }, '~ud': function(event) { - var query = event.input[1]; + var query = event.input[1]; var reqUrl = 'http://api.urbandictionary.com/v0/define?term=' + encodeURI(query); request(reqUrl, function(error, response, body) { - var result = JSON.parse(body); - if(_.has(result, 'result_type') && result.result_type != 'no_results') { - event.reply(query + ': ' + result.list[0].definition.split('\n')[0]); - } else { - event.reply(event.user + ': No definition found.'); - } + try { + var result = JSON.parse(body); + if(_.has(result, 'result_type') && result.result_type != 'no_results') { + event.reply(query + ': ' + result.list[0].definition.split('\n')[0]); + } else { + event.reply(event.user + ': No definition found.'); + } + } catch(err) { } }); } };