From 66a6fec79262db3bf00c6bd842c1d2aa23c6d5ea Mon Sep 17 00:00:00 2001 From: Drewler Date: Sun, 18 Mar 2018 22:30:38 +0100 Subject: [PATCH] Error messages referencing FAQ. Closes #14 --- lib/logger/index.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/logger/index.js b/lib/logger/index.js index 96bd39b..443e679 100644 --- a/lib/logger/index.js +++ b/lib/logger/index.js @@ -11,13 +11,17 @@ goblin.errorEmitter.on('error', function (exception, error) { }); }); -function goblinException(prefix, log) { +function goblinException(prefix, code, log) { this.prefix = prefix; this.log = log; this.toString = function() { return (this.prefix ? this.prefix + ': ' : '') + this.log; }; + this.faqString = function() { + return 'Check the F.A.Q. at https://github.com/GoblinDBRocks/GoblinDB/wiki/Errors#' + + code.toLowerCase() + ' for more information. 👺'; + }; } module.exports = function(code, error, type) { @@ -25,18 +29,13 @@ module.exports = function(code, error, type) { const prefix = goblin.config.logPrefix; const log = errors[code] || code; - const exception = new goblinException(prefix, log); + const exception = new goblinException(prefix, code, log); // Always emit error event goblin.errorEmitter.emit('error', exception, error || {}); - if (currentMode === mode.strict) { throw exception.toString(); } else if (currentMode === mode.development) { - if (error) { - console[type || 'error'](exception.toString(), error); - } else { - console[type || 'error'](exception.toString()); - } + console[type || 'error'](exception.toString(), exception.faqString(), error ? error : '' ); } -}; \ No newline at end of file +};