From 7288d14fac8dff75974fc445f85f121ee38b609e Mon Sep 17 00:00:00 2001 From: Drew Warren Date: Tue, 17 Jan 2017 12:01:02 -0700 Subject: [PATCH] Separate handling errors Prevent res.body from being called if res is not defined. Close #16 --- lib/register-new-account.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/register-new-account.js b/lib/register-new-account.js index 7972582..29b32ca 100644 --- a/lib/register-new-account.js +++ b/lib/register-new-account.js @@ -24,7 +24,11 @@ module.exports.create = function (deps) { function getTerms(err, res) { var links; - if (err || Math.floor(res.statusCode/100)!==2) { + if (err) { + return handleErr(err, 'Registration request failed: ' + err.toString()); + } + + if (Math.floor(res.statusCode/100)!==2) { return handleErr(err, 'Registration request failed: ' + res.body.toString('utf8')); }