Generate proper returnable object according to received error type
@param {*} error
@return {Object}
490014
function generateReturnableError(error) {
    if (_.isError(error)) {
        return {
            body: {error: error.message},
            options: {code: httpCodes.INTERNAL_SERVER_ERROR}
        };
    }
    if (_.isString(error)) {
        return {
            body: {error},
            options: {code: httpCodes.INTERNAL_SERVER_ERROR}
        };
    }
    if (_.isObject(error) && !_.isFunction(error)) {
        if (_.isArray(error)) {
            return {
                body: {error},
                options: {code: httpCodes.INTERNAL_SERVER_ERROR}
            };
        }
        let code = error.code || httpCodes.INTERNAL_SERVER_ERROR;
        delete error.code;
        return {
            body: error,
            options: {code}
        };
    }
    if (_.isFunction(error)) {
        return {
            body: {error: 'Incorrect error type "function"'},
            options: {code: httpCodes.INTERNAL_SERVER_ERROR}
        };
    }
    return {
        body: {error: 'Unexpected error format'},
        options: {code: httpCodes.INTERNAL_SERVER_ERROR}
    };
}
285244
function errorSerializer (err) {
  if (!err || !err.stack) return err
  const obj = {
    message: err.message,
    name: err.name,
    code: err.code,
    stack: getErrorStack(err)
  }
  return obj
}
56819
function createError (err, target) {
  return { status: 'error', target: target, message: err, timestamp: Date.now() }
}
794173
function normalizeError(err) {
  let message = 'Unknown error';

  if (err) {
    if (err instanceof Error) {
      return err;
    }

    message = err.stack || err.message || err;
  }

  return new Error(message);
}
526026
function assertError(result, error) {
  if (typeof error === 'function') {
    if (!(result instanceof error || error(result) === true)) {
      throw result
    }
  } else if (typeof error === 'string') {
    assert(result.message.includes(error), 'Error message is incorrect')
  } else if (error instanceof RegExp) {
    assert(
      error.test(result.message),
      `Expected ${result.message} to match ${error}`,
    )
  } else {
    invariant(
      typeof error === 'boolean',
      'The given `error` must be a function, string, boolean, or RegExp',
    )
  }
}
1172958
function formatError(e) {
  if (!e.error) {
    return e.message;
  }

  // Don't show stacktrace on informational errors
  if (e.error instanceof Information) {
    return e.error.message;
  }

  // PluginError
  if (typeof e.error.showStack === "boolean") {
    return e.error.toString();
  }
  // Normal error
  if (e.error.stack) {
    return e.error.stack;
  }
  // Unknown (string, number, etc.)
  return new Error(String(e.error)).stack;
}
116508
function VError()
{
	var args, obj, parsed, cause, ctor, message, k;

	args = Array.prototype.slice.call(arguments, 0);

	/*
	 * This is a regrettable pattern, but JavaScript's built-in Error class
	 * is defined to work this way, so we allow the constructor to be called
	 * without "new".
	 */
	if (!(this instanceof VError)) {
		obj = Object.create(VError.prototype);
		VError.apply(obj, arguments);
		return (obj);
	}

	/*
	 * For convenience and backwards compatibility, we support several
	 * different calling forms.  Normalize them here.
	 */
	parsed = parseConstructorArguments({
	    'argv': args,
	    'strict': false
	});

	/*
	 * If we've been given a name, apply it now.
	 */
	if (parsed.options.name) {
		mod_assertplus.string(parsed.options.name,
		    'error\'s "name" must be a string');
		this.name = parsed.options.name;
	}

	/*
	 * For debugging, we keep track of the original short message (attached
	 * this Error particularly) separately from the complete message (which
	 * includes the messages of our cause chain).
	 */
	this.jse_shortmsg = parsed.shortmessage;
	message = parsed.shortmessage;

	/*
	 * If we've been given a cause, record a reference to it and update our
	 * message appropriately.
	 */
	cause = parsed.options.cause;
	if (cause) {
		mod_assertplus.ok(mod_isError(cause), 'cause is not an Error');
		this.jse_cause = cause;

		if (!parsed.options.skipCauseMessage) {
			message += ': ' + cause.message;
		}
	}

	/*
	 * If we've been given an object with properties, shallow-copy that
	 * here.  We don't want to use a deep copy in case there are non-plain
	 * objects here, but we don't want to use the original object in case
	 * the caller modifies it later.
	 */
	this.jse_info = {};
	if (parsed.options.info) {
		for (k in parsed.options.info) {
			this.jse_info[k] = parsed.options.info[k];
		}
	}

	this.message = message;
	Error.call(this, message);

	if (Error.captureStackTrace) {
		ctor = parsed.options.constructorOpt || this.constructor;
		Error.captureStackTrace(this, ctor);
	}

	return (this);
}
2643
function customError(name, error) {
  return {
    error: error,
    message: error.message,
    name: name
  };
}
761600
function error(name, code) {

  return function (_Error) {
    _inherits(MJMLError, _Error);

    function MJMLError(message) {
      _classCallCheck(this, MJMLError);

      var _this = _possibleConstructorReturn(this, (MJMLError.__proto__ || Object.getPrototypeOf(MJMLError)).call(this, '[MJMLError] ' + name + ': ' + message));

      _this.status = code;
      return _this;
    }

    return MJMLError;
  }(Error);
}
480761
function formatError(error) {
        function localize(key) {
            if (Strings[key]) {
                return Strings[key];
            }
            console.log("Unknown installation error", key);
            return Strings.UNKNOWN_ERROR;
        }

        if (Array.isArray(error)) {
            error[0] = localize(error[0]);
            return StringUtils.format.apply(window, error);
        } else {
            return localize(error);
        }
    }
770149
function createError(status, message) {
  var err = new Error(message);
  err.status = status;
  return err;
}
4398
function format(errors, type) {
  return errors
    .filter(isDefaultError)
    .reduce((accum, error) => (
      accum.concat(displayError(type, error))
    ), []);
}
1065245
function erroz(error) {

    var errorFn = function (data) {

        //apply all attributes on the instance
        for (var errKey in errorFn.prototype) {
            if (errorFn.prototype.hasOwnProperty(errKey)) {
                this[errKey] = errorFn.prototype[errKey];
            }
        }

        //overwrite message if invoked with string
        if (typeof data === "string") {
            this.message = data;
            data = {};
        }

        this.data = data || {};

        this.message = this.message || erroz.options.renderMessage(error.template || "", this.data);

        errorFn.super_.call(this, this.constructor);
    };

    util.inherits(errorFn, AbstractError);

    //add static error properties (name, status, etc)
    for (var errKey in error) {
        if (error.hasOwnProperty(errKey)) {
            errorFn.prototype[errKey] = error[errKey];
        }
    }

    /**
     * return an object containing only JSend attributes
     * @returns {{status: *, code: *, message: *, data: (*|string|Object[]|Object|String)}}
     */
    errorFn.prototype.toJSend = function () {
        var data = this.data;

        if (erroz.options.includeStack && this.stack) {
            data.stack = this.stack;
        }

        if (!this.status) {
            this.status = deriveStatusFromStatusCode(this.statusCode);
        }

        return {
            status: this.status,
            code: this.code,
            message: this.message,
            data: data
        };
    };

    return errorFn;
}
720894
function getError(number, countryCode) {
    try {
        var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance();
        var numberObj = phoneUtil.parseAndKeepRawInput(number, countryCode);
        return phoneUtil.isPossibleNumberWithReason(numberObj);
    } catch (e) {
        //console.log(e);

        // here I convert thrown errors into ValidationResult enums (if possible)
        if (e == i18n.phonenumbers.Error.INVALID_COUNTRY_CODE) {
            return i18n.phonenumbers.PhoneNumberUtil.ValidationResult.INVALID_COUNTRY_CODE;
        }
        if (e == i18n.phonenumbers.Error.NOT_A_NUMBER) {
            return 4;
        }
        if (e == i18n.phonenumbers.Error.TOO_SHORT_AFTER_IDD || e == i18n.phonenumbers.Error.TOO_SHORT_NSN) {
            return i18n.phonenumbers.PhoneNumberUtil.ValidationResult.TOO_SHORT;
        }
        if (e == i18n.phonenumbers.Error.TOO_LONG) {
            return i18n.phonenumbers.PhoneNumberUtil.ValidationResult.TOO_LONG;
        }

        // broken
        return -99;
    }
}
982818
function(i){
				return function(resp){
					if(that._errorHandler) { that._errorHandler(i, resp); }
					else { throw new Error(resp); }
				};
			}
809186
function toJSON( err ) {
	var keys;
	var out;
	var i;
	if ( !( err instanceof Error ) ) {
		throw new TypeError( 'invalid input argument. Must provide an error object. Value: `' + err + '`.' );
	}
	out = {};

	// Guaranteed properties:
	out.type = typeName( err );
	out.message = err.message;

	// Possible general error properties...
	if ( err.name ) {
		out.name = err.name;
	}
	if ( err.stack ) {
		out.stack = err.stack;
	}
	// Possible Node.js (system error) properties...
	if ( err.code ) {
		out.code = err.code;
	}
	if ( err.errno ) {
		out.errno = err.errno;
	}
	if ( err.syscall ) {
		out.syscall = err.syscall;
	}
	// Any enumerable properties...
	keys = getKeys( err );
	for ( i = 0; i < keys.length; i++ ) {
		out[ keys[i] ] = copy( err[ keys[i] ] );
	}
	return out;
}
908654
function (err) {
    "use strict";

    var message = '';

    if (typeof err === 'string') {
      return new Error(err);

    } else if (typeof err === 'object') {

      if (err.cause) {
        // probably a webdriver error
        try {
          message = JSON.parse(err.cause.value.message).errorMessage;
        } catch ($) {
          message = err.cause.value.message;
        }
      } else {
        message = err.message || err.toString();
      }
      return new Error(message);
    }
    return new Error(err.toString());
  }