From f4c929a3ccccc92ae6c53f49c017867bc7e08181 Mon Sep 17 00:00:00 2001 From: Markus Stefanko Date: Thu, 8 Mar 2018 13:03:26 +0700 Subject: [PATCH] xml_parser only needed there --- index.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 7ac1c71..72a2098 100644 --- a/index.js +++ b/index.js @@ -26,12 +26,7 @@ var GoogleSpreadsheet = function( ss_key, auth_id, options ){ options = options || {}; - var xml_parser = new xml2js.Parser({ - // options carried over from older version of xml2js - // might want to update how the code works, but for now this is fine - explicitArray: false, - explicitRoot: false - }); + if ( !ss_key ) { throw new Error("Spreadsheet key not provided."); @@ -162,8 +157,18 @@ var GoogleSpreadsheet = function( ss_key, auth_id, options ){ if ( body ){ + var xml_parser = new xml2js.Parser({ + // options carried over from older version of xml2js + // might want to update how the code works, but for now this is fine + explicitArray: false, + explicitRoot: false + }); xml_parser.parseString(body, function(err, result){ - if ( err ) return cb( err ); + if ( err ) { + xml_parser = null; + body = null; + return cb( err ); + } if(cb.length == 3) { cb( null, result, body ); }else{