/*
 This helper modules allows us to create different type of errors we can throw
*/
function customError(message, errorName)
{
  this.name = errorName || "Error";
  this.message = message;

  var stackParts = new Error().stack.split("\n");
  stackParts.splice(0,2);
  stackParts.unshift(this.name + ": " + message);

  this.stack = stackParts.join("\n");
}
customError.prototype = Error.prototype;

module.exports = customError;

/**
 * CustomError
 *
 * This helper modules allows us to create different type of errors we can throw
 *
 * @class CustomError
 * @extends {Error}
 */
class CustomError extends Error {
  /**
   * Creates an instance of CustomError.
   * @param {*} message
   * @param {string} [name='Error'] a custom name for the error object
   * @memberof CustomError
   */
  constructor(message, name = 'Error') {
    super(message);
    this.name = name;
    Error.captureStackTrace(this, this.constructor);
  }
}

module.exports = CustomError;

rewrite the module using class syntax