UNPKG

react-native-unit-components

Version:

Unit React Native components

34 lines (32 loc) 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.promiseRejectToUNVPErrorType = exports.isUNVPError = exports.isUNNativePromiseReject = void 0; var _types = require("./types"); /* eslint-disable @typescript-eslint/no-explicit-any */ const isUNVPError = error => { return 'code' in error && 'description' in error && 'type' in error && isUNVPErrorType(error.type) && 'correlationId' in error; }; exports.isUNVPError = isUNVPError; const isUNVPErrorType = type => { return Object.values(_types.UNVPErrorType).includes(type); }; const isUNNativePromiseReject = error => { return 'code' in error && 'message' in error; }; exports.isUNNativePromiseReject = isUNNativePromiseReject; const promiseRejectToUNVPErrorType = error => { // validate the shape of a promise reject we get from iOS/Android native if (!isUNNativePromiseReject(error)) { return null; } const parsedError = JSON.parse(error.message); // validate the shape of an error we get from VDE SDK if (!isUNVPError(parsedError)) { return null; } return parsedError.type; }; exports.promiseRejectToUNVPErrorType = promiseRejectToUNVPErrorType; //# sourceMappingURL=helpers.js.map