From dcf89a4e1119decc48b97cc1d3c921ff5418e7b9 Mon Sep 17 00:00:00 2001 From: Christian Becker Date: Thu, 21 Jan 2016 18:35:16 +0100 Subject: [PATCH] Prevent TypeError in case of non-match --- periscope.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/periscope.js b/periscope.js index a2a6855..b2eac90 100644 --- a/periscope.js +++ b/periscope.js @@ -1,8 +1,12 @@ var request = require('request'); function periscope(url, callback) { - var id = url.match(/periscope.tv\/w\/(.*)/i)[1]; + var matches = url.match(/periscope.tv\/w\/(.*)/i); + if (!matches) { + return; + } + var id = matches[1]; var api = 'https://api.periscope.tv/api/v2/getAccessPublic?broadcast_id=' + id; request(api, function(error, response, body) {