You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
961 B

4 years ago
  1. var baseGetTag = require('./_baseGetTag'),
  2. isObjectLike = require('./isObjectLike'),
  3. isPlainObject = require('./isPlainObject');
  4. /** `Object#toString` result references. */
  5. var domExcTag = '[object DOMException]',
  6. errorTag = '[object Error]';
  7. /**
  8. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  9. * `SyntaxError`, `TypeError`, or `URIError` object.
  10. *
  11. * @static
  12. * @memberOf _
  13. * @since 3.0.0
  14. * @category Lang
  15. * @param {*} value The value to check.
  16. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  17. * @example
  18. *
  19. * _.isError(new Error);
  20. * // => true
  21. *
  22. * _.isError(Error);
  23. * // => false
  24. */
  25. function isError(value) {
  26. if (!isObjectLike(value)) {
  27. return false;
  28. }
  29. var tag = baseGetTag(value);
  30. return tag == errorTag || tag == domExcTag ||
  31. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
  32. }
  33. module.exports = isError;