UNPKG

react-native-recaptcha-enterprise

Version:

Google Enterprise reCaptcha library for React-Native. Real native implementation for iOS and Android.

50 lines (48 loc) 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.recaptchaErrorHandler = recaptchaErrorHandler; var _types = require("./types"); function mapPlatformErrorsIntoCommonType(errorType) { const errorCode = parseInt(errorType, 10); if (errorCode) { if (errorCode <= 5 || errorCode === 100) { return ( // @ts-ignore _types.RecaptchaErrorCodes[errorType] || _types.RecaptchaErrorCodes.RecaptchaErrorCodeUnknown ); } console.warn('[Recaptcha Enterprise]: there is unhandled (not provided) error code: ' + `'${errorCode}'.` + ' Please, inform maintainer of this package via GitHub.'); } if (errorType) { return ( // @ts-ignore _types.RecaptchaErrorCodes[errorType] || _types.RecaptchaErrorCodes.RecaptchaErrorCodeUnknown ); } return _types.RecaptchaErrorCodes.RecaptchaErrorCodeUnknown; } /** * Parse error object, map it into {@link RecaptchaErrorType} and decide should be thrown or not. * * @param {*} err - A caught error-object on Promise-level. * @param {boolean} [throwable=true] - Optional parameter to define throw immediately * or take error result and handle by your-self. * * @return {RecaptchaErrorType} In case of not throwable. * * @throws {RecaptchaErrorType} */ function recaptchaErrorHandler(err, throwable = true) { const errorBody = { code: err !== null && err !== void 0 && err.code ? mapPlatformErrorsIntoCommonType(err.code) : _types.RecaptchaErrorCodes.RecaptchaErrorCodeUnknown, message: (err === null || err === void 0 ? void 0 : err.message) || 'Unexpected error', rawData: err }; if (throwable) { throw errorBody; } return errorBody; } //# sourceMappingURL=recaptchaErrorHandler.js.map