Skip to content

Instantly share code, notes, and snippets.

@laustdeleuran
Created February 6, 2012 12:29
Show Gist options
  • Save laustdeleuran/1751854 to your computer and use it in GitHub Desktop.
Save laustdeleuran/1751854 to your computer and use it in GitHub Desktop.
Vertic Lib Error Class Extends Log
var _Error = function(){};
_Error.prototype = new _Log();
_Error.prototype.parent = _Log.prototype;
_Error.prototype.write = function(arg,status,msg,die){
var orgArg = arg;
// Set optional parameters
if (typeof status === 'undefined') status = 'unknown';
if (typeof msg === 'undefined') msg = '';
if (typeof die !== 'boolean') die = false;
// Add metadata
arg = this.addMeta(arg);
if (this.meta) {
arg.error = true;
arg.errorType = status.toString();
arg.errorMsg = msg.toString();
}
// Push object to internal log
this.history.push(arg);
// Throw JS error if needed or simple warning if possible
if (die) {
throw new Error(status+': '+msg);
} else {
try { console.warn(status+': '+msg); console.warn(arg); } catch(err) {}
}
// Make loud debugging noises
if (this.debug || typeof forceDebug !== 'undefined') { alert('Error: ' + orgArg) }
// Call to very basic DOM based console for browsers with no native console
this.callDomConsole(arg);
// Return base argument
return orgArg;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment