Hi all,
I have a question about the error managment within servoy application server.
The active solution has an event named “onError”, what I would like to obtain is to manage the errors to don’t let the client goes stop but, if it’s possible, to write also the error into the server log.
At now I’ve an headless client that sometimes goes in error. I would handling the error to writing a personal log into the table AND on the server log WITHOUT interrupt the headless client execution (a batch work is loaded).
How can I write the function to link to “onError” event to write the error message on the server log without interrupt the client?
Thanks in advance
Marco
This should get you started:
function onErrorHandler(ex)
{
// Handles the error
application.output('Exception Object: ' + ex)
application.output('MSG: ' + ex.getMessage())
application.output('StackTrace: ' + ex.getStackTrace())
// Create an entry in the error log
/** @type {JSFoundset<db:/sintpro_mods/sintpro_errors_log>} */
var _errors = databaseManager.getFoundSet('sintpro_mods','sintpro_errors_log')
_errors.newRecord()
var _msg = 'Internal Error ID: '+ _errors.sintpro_errors_log_id
_msg += '\n\nException Object: ' + ex
_msg += '\nMessage: ' + ex.getMessage()
_errors.loginslog_id = forms.Main.vLoginslogId
_errors.error_message = ex.getMessage()
// Save some more details
var _details = 'Framework Status:'
_details += '\n----------------------------------'
_details += '\nActive Form: '+ scopes.nav.getActiveForm()
_details += '\nAutoSave Status: '+ databaseManager.getAutoSave()
_details += '\nsintpro_db_name = '+ globals.sintpro_db_name
_details += '\nsintpro_schema_name = '+ globals.sintpro_schema_name
_details += '\nUser Data = '+ globals.user_record
_details += '\nnavBar = '+ scopes.nav.navBar
_details += '\nrecInfo = '+ scopes.nav.recInfoTooltip
_details += '\n----------------------------------'
/** @type {JSDataSet} */
var _locks = plugins.UserManager.Server().getLocks()
if(_locks.getMaxRowIndex() > 0)
{
_details += '\nLocks: '+ _locks.getAsText(',','/n','',true)
}
// Get details from modules
if(globals.lfGetClientStatusDetails)
{
_details += '\n'+globals.lfGetClientStatusDetails()
}
if (ex instanceof ServoyException)
{
/** @type {ServoyException} */
var servoyEx = ex
application.output('is a ServoyException')
application.output('ServoyException Errorcode: ' + servoyEx.getErrorCode())
_errors.error_code = servoyEx.getErrorCode()
_msg += '\nServoyException Errorcode: ' + servoyEx.getErrorCode()
if (servoyEx.getErrorCode() == ServoyException.SAVE_FAILED)
{
// Get the failed records after a save
var array = databaseManager.getFailedRecords()
for (var i = 0; i < array.length; i++)
{
var record = array[i];
application.output(record.exception);
if (record.exception instanceof DataException)
{
/** @type {DataException} */
var recException = record.exception
_details += '\nSQL Status:'
_details += '\n----------------------------------'
application.output('SQL: ' + recException.getSQL())
application.output('SQLState: ' + recException.getSQLState())
application.output('VendorErrorCode: ' + recException.getVendorErrorCode())
_details += 'SQL: ' + recException.getSQL()
_details += '\nSQLState: ' + recException.getSQLState()
_details += '\nVendorErrorCode: ' + recException.getVendorErrorCode()
}
}
// Save the error log record
_errors.error_details = _details
databaseManager.saveData(_errors.getRecord(1))
// if returns false or no return, error is not reported to client; if returns true error is reported
return false
}
}
// Save the error log record
_errors.error_details = _details
databaseManager.saveData(_errors.getRecord(1))
// Notify the user
_msg += '\n\nPlease fully report this error message if you request assistence.'
if(application.getApplicationType() == APPLICATION_TYPES.SMART_CLIENT)
{
globals.DIALOGS.showErrorDialog(i18n.getI18NMessage('servoy.general.error'),_msg,i18n.getI18NMessage('servoy.button.ok'))
}
else
{
// FIXME: the continuation has problems and the error dialog cannot be closed in WC, let's wait for 5.2.10
globals.DIALOGS.showErrorDialog(i18n.getI18NMessage('servoy.general.error'),_msg,i18n.getI18NMessage('servoy.button.ok'))
}
// if returns false or no return, error is not reported to client; if returns true error is reported
return false;
}