is_error.js 911 B

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = isError;
  6. var _prettyFormat = require('pretty-format');
  7. var _prettyFormat2 = _interopRequireDefault(_prettyFormat);
  8. function _interopRequireDefault(obj) {
  9. return obj && obj.__esModule ? obj : {default: obj};
  10. }
  11. function isError(potentialError) {
  12. // duck-type Error, see #2549
  13. const isError =
  14. typeof potentialError === 'object' &&
  15. typeof potentialError.message === 'string' &&
  16. typeof potentialError.name === 'string';
  17. const message = isError
  18. ? null
  19. : `Failed: ${(0, _prettyFormat2.default)(potentialError, {maxDepth: 3})}`;
  20. return {isError: isError, message: message};
  21. }
  22. /**
  23. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  24. *
  25. * This source code is licensed under the MIT license found in the
  26. * LICENSE file in the root directory of this source tree.
  27. *
  28. *
  29. */