diff --git a/core/enig_error.js b/core/enig_error.js index 69722a85..adf5eef6 100644 --- a/core/enig_error.js +++ b/core/enig_error.js @@ -2,11 +2,14 @@ 'use strict'; class EnigError extends Error { - constructor(message) { + constructor(message, code, reason, reasonCode) { super(message); this.name = this.constructor.name; this.message = message; + this.code = code; + this.reason = reason; + this.reasonCode = reasonCode; if(typeof Error.captureStackTrace === 'function') { Error.captureStackTrace(this, this.constructor); @@ -16,4 +19,12 @@ class EnigError extends Error { } } -exports.EnigError = EnigError; \ No newline at end of file +class EnigMenuError extends EnigError { } + +exports.EnigError = EnigError; +exports.EnigMenuError = EnigMenuError; + +exports.Errors = { + General : (reason, reasonCode) => new EnigError('An error occurred', -33000, reason, reasonCode), + MenuStack : (reason, reasonCode) => new EnigMenuError('Menu stack error', -33001, reason, reasonCode), +}; diff --git a/core/menu_stack.js b/core/menu_stack.js index 98a171b9..84e6a6e0 100644 --- a/core/menu_stack.js +++ b/core/menu_stack.js @@ -3,6 +3,7 @@ // ENiGMA½ const loadMenu = require('./menu_util.js').loadMenu; +const Errors = require('./enig_error.js').Errors; // deps const _ = require('lodash'); @@ -57,16 +58,16 @@ module.exports = class MenuStack { if(_.isArray(menuConfig.next)) { nextMenu = this.client.acs.getConditionalValue(menuConfig.next, 'next'); if(!nextMenu) { - return cb(new Error('No matching condition for \'next\'!')); + return cb(Errors.MenuStack('No matching condition for "next"', 'NOCONDMATCH')); } } else if(_.isString(menuConfig.next)) { nextMenu = menuConfig.next; } else { - return cb(new Error('Invalid or missing \'next\' member in menu config!')); + return cb(Errors.MenuStack('Invalid or missing "next" member in menu config', 'BADNEXT')); } if(nextMenu === currentModuleInfo.name) { - return cb(new Error('Menu config \'next\' specifies current menu!')); + return cb(Errors.MenuStack('Menu config "next" specifies current menu', 'ALREADYTHERE')); } this.goto(nextMenu, { }, cb); @@ -90,7 +91,7 @@ module.exports = class MenuStack { return this.goto(previousModuleInfo.name, opts, cb); } - return cb(new Error('No previous menu available!')); + return cb(Errors.MenuStack('No previous menu available', 'NOPREV')); } goto(name, options, cb) { @@ -104,7 +105,7 @@ module.exports = class MenuStack { if(currentModuleInfo && name === currentModuleInfo.name) { if(cb) { - cb(new Error('Already at supplied menu!')); + cb(Errors.MenuStack('Already at supplied menu', 'ALREADYTHERE')); } return; } diff --git a/core/message.js b/core/message.js index 65fe80f9..e1d3e4fd 100644 --- a/core/message.js +++ b/core/message.js @@ -139,7 +139,7 @@ Message.createMessageUUID = function(areaTag, modTimestamp, subject, body) { body = iconvEncode(body.replace(/\r\n|[\n\v\f\r\x85\u2028\u2029]/g, '').trim(), 'CP437'); return uuid.unparse(createNamedUUID(ENIGMA_MESSAGE_UUID_NAMESPACE, Buffer.concat( [ areaTag, modTimestamp, subject, body ] ))); -} +}; Message.getMessageIdByUuid = function(uuid, cb) { msgDb.get( diff --git a/core/view_controller.js b/core/view_controller.js index dcc25d31..f2fbb366 100644 --- a/core/view_controller.js +++ b/core/view_controller.js @@ -49,7 +49,11 @@ function ViewController(options) { menuUtil.handleAction(self.client, formData, actionBlock, (err) => { if(err) { // :TODO: What can we really do here? - self.client.log.warn( { err : err }, 'Error during handleAction()'); + if('ALREADYTHERE' === err.reasonCode) { + self.client.log.trace( err.reason ); + } else { + self.client.log.warn( { err : err }, 'Error during handleAction()'); + } } self.waitActionCompletion = false;