Manejo de errores mejorado

This commit is contained in:
Juan Ferrer Toribio 2017-09-22 13:11:55 +02:00
parent ff0efae219
commit 21d4e7d745
1 changed files with 43 additions and 37 deletions

View File

@ -27,7 +27,7 @@ var App =
_onLoad: function ()
{
// Inicializa variables globales
// Initializes the global variables
var split = Verdnatura.commandLine.match(/(?:[^\s"]+|"[^"]*")+/g);
@ -42,7 +42,7 @@ var App =
this.compressFile = this.getEnv ('TEMP') +'\\'+ this.module +'.7z';
this.mdbFile = this.moduleDir +'\\'+ this.module +'.mdb';
// Crea las entradas necesarias en el registro
// Creates the necessary registry entries
var configured = this.regRead (Conf.regPath, 'configured');
@ -50,7 +50,7 @@ var App =
{
var path;
// Crea las entradas de configuración de Access
// Creates the Access configuration entries
path = 'HKCU\\Software\\Microsoft\\Office\\11.0\\Access\\Settings';
this.regWrites (path, 'REG_DWORD', {
@ -62,7 +62,7 @@ var App =
path = 'HKCU\\Software\\Microsoft\\Office\\11.0\\Access\\Security';
this.regWrite (path, 'Level', 1, 'REG_DWORD');
// Crea el ODBC de MySQL
// Creates the MySQL ODBC connection
var driverPath = this.getEnv ('ProgramFiles')
+'\\MySQL\\Connector ODBC 5.1\\myodbc5.dll';
@ -83,7 +83,7 @@ var App =
params
);
// Crea el ODBC de PosgreSQL
// Creates the PosgreSQL ODBC connection
var driverPath = this.getEnv ('ProgramFiles')
+'\\psqlODBC\\0804\\bin\\psqlodbc35w.dll';
@ -104,12 +104,12 @@ var App =
params
);
// Marca la aplicación como configurada
// Marks the application as configured
this.regWrite (Conf.regPath, 'configured', 1, 'REG_DWORD');
}
// Carga los datos del formulario
// Loads the form data
var user = this.regRead (Conf.dsPath, 'UID');
var password = this.regRead (Conf.dsPath, 'PWD');
@ -196,15 +196,43 @@ var App =
this.regWrite (Conf.dsPath, 'UID', user, 'REG_SZ');
this.regWrite (Conf.dsPath, 'PWD', password, 'REG_SZ');
// Obtiene la última versión usando la conexión ODBC de MySQL
// Gets the last version number usign the MySQL ODBC connection
var mysqlConn = new ActiveXObject ('ADODB.Connection');
var dbErrors = mysqlConn.errors;
try {
dbErrors.clear ();
mysqlConn.open (Conf.dsName);
}
catch (e) {
throw new Error ('Usuario o contraseña incorrectos');
catch (e)
{
if (dbErrors.count > 0)
{
var errorMsg;
var dbError = dbErrors.item(0);
alert (dbError.description );
switch (dbError.NativeError)
{
case 1045: // Access denied
errorMsg = 'Usuario o contraseña incorrectos';
break;
case 2003: // Can't connect
errorMsg = 'No se ha podido conectar con el '
+'servidor, comprueba que tienes conexión a '
+'Internet y que el servidor está accesible';
break;
default:
errorMsg = dbError.description;
}
dbErrors.clear();
throw new Error (errorMsg);
}
else
throw e;
}
var sql = 'SELECT version FROM versiones WHERE programa = \''+ this.module +'\'';
@ -214,7 +242,7 @@ var App =
rs.close ();
mysqlConn.close ();
// Obtiene el número de versión local del archivo MDB
// Obtains the local version number from the MDB file
var localVersion = -1;
@ -232,14 +260,16 @@ var App =
}
catch (e) {}
// Compara la versión local con la última versión
// Compares the local version with the las version
if (localVersion < lastVersion)
{
this._disableUi (true, 'Actualizando');
var request = new ActiveXObject ('MSXML2.XMLHTTP');
request.open ('GET', this.remoteFile +'?'+ new Date().getTime(), true);
request.onreadystatechange = function () {App._onRequestReady (request);};
request.onreadystatechange = function () {
App._onRequestReady (request);
};
request.send ();
}
else
@ -276,33 +306,9 @@ var App =
if (this.fso.fileExists (this.mdbFile))
this.fso.deleteFile (this.mdbFile);
// XXX: Code for the old installer modules
var oldModules = {
'tpv': 'TPV_MySQL2',
'ent': 'ENT_MySQL',
'com': 'COM_MySQL',
'enc': 'ENC_MySQL',
'eti': 'ETI',
'lab': 'LAB_MySQL'
};
var oldMdb = this.moduleDir +'\\'+ oldModules[this.module] +'.mdb';
if (this.fso.fileExists (oldMdb))
this.fso.deleteFile (oldMdb);
// XXX: End
this.run ('7za e "'+ this.compressFile +'" -o"'+ this.moduleDir +'"', true);
this.fso.deleteFile (this.compressFile);
// XXX: Code for the old installer modules
if (!this.fso.fileExists (this.mdbFile) && this.fso.fileExists (oldMdb))
this.fso.moveFile (oldMdb, this.mdbFile);
// XXX: End
}
catch (e)
{