UNPKG

874 BJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.default = isError;
7var _prettyFormat = require('pretty-format');
8/**
9 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
10 *
11 * This source code is licensed under the MIT license found in the
12 * LICENSE file in the root directory of this source tree.
13 */
14
15function isError(
16 // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
17 potentialError
18) {
19 // duck-type Error, see #2549
20 const isError =
21 potentialError !== null &&
22 typeof potentialError === 'object' &&
23 typeof potentialError.message === 'string' &&
24 typeof potentialError.name === 'string';
25 const message = isError
26 ? null
27 : `Failed: ${(0, _prettyFormat.format)(potentialError, {
28 maxDepth: 3
29 })}`;
30 return {
31 isError,
32 message
33 };
34}