UNPKG

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