From 13717bd4f70398d4b2e4c99a5b7729323e3c3ae3 Mon Sep 17 00:00:00 2001 From: Jon Nettleton Date: Sat, 3 Jan 2015 10:03:43 +0100 Subject: [PATCH] Catch undefined content-type headers If content-type is undefined then catch the exception and set it to empty just as is done for the body. --- src/plugins/irc-events/link.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plugins/irc-events/link.js b/src/plugins/irc-events/link.js index c3b22447..b83a4a4f 100644 --- a/src/plugins/irc-events/link.js +++ b/src/plugins/irc-events/link.js @@ -109,15 +109,21 @@ function fetch(url, cb) { .pipe(es.wait(function(err, data) { if (err) return; var body; + var type; try { body = JSON.parse(data); } catch(e) { body = {}; } + try { + type = req.response.headers['content-type'].split(/ *; */).shift(); + } catch(e) { + type = {}; + } data = { text: data, body: body, - type: req.response.headers['content-type'].split(/ *; */).shift() + type: type }; cb(data); }));