Added error checking at self update npm install

Noah Zalev committed Apr 18, 2021 at 18:11 UTC fad0f767caba5f934bb125ac904cffcc84dc0c39
1 file changed +7 -2
meshcentral.js
+7 -2
@@ -445,11 +445,16 @@ function CreateMeshCentralServer(config, args) {
445 var npmproxy = ((typeof obj.args.npmproxy == 'string') ? (' --proxy ' + obj.args.npmproxy) : '');
446 var env = Object.assign({}, process.env); // Shallow clone
447 if (typeof obj.args.npmproxy == 'string') { env['HTTP_PROXY'] = env['HTTPS_PROXY'] = env['http_proxy'] = env['https_proxy'] = obj.args.npmproxy; }
448 - var xxprocess = child_process.exec(npmpath + ' install meshcentral' + version + npmproxy, { maxBuffer: Infinity, cwd: obj.parentpath, env: env }, function (error, stdout, stderr) { });
448 + var xxprocess = child_process.exec(npmpath + ' install meshcentral' + version + npmproxy, { maxBuffer: Infinity, cwd: obj.parentpath, env: env }, function (error, stdout, stderr) {
449 + if ((error != null) && (error != '')) { console.log('Update failed: ' + error); }
450 + });
451 xxprocess.data = '';
452 xxprocess.stdout.on('data', function (data) { xxprocess.data += data; });
453 xxprocess.stderr.on('data', function (data) { xxprocess.data += data; });
452 - xxprocess.on('close', function (code) { console.log('Update completed...'); setTimeout(function () { obj.launchChildServer(startArgs); }, 1000); });
454 + xxprocess.on('close', function (code) {
455 + if (code == 0) { console.log('Update completed...'); }
456 + setTimeout(function () { obj.launchChildServer(startArgs); }, 1000);
457 + });
458 } else {
459 if (error != null) {
460 // This is an un-expected restart