From f6b5e5b0ad7d03671b8f4a94717d3d75f610dd56 Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja Date: Mon, 5 Aug 2024 16:43:48 +0530 Subject: [PATCH] fix: parse exn error handle --- src/Components/AddressPaymentInput.res | 2 +- src/Components/BillingNamePaymentInput.res | 2 +- src/Components/BlikCodePaymentInput.res | 2 +- src/Components/EmailPaymentInput.res | 2 +- src/Components/FullNamePaymentInput.res | 2 +- src/Components/FullScreenPortal.res | 2 +- src/Components/PaymentLoader.res | 9 +++++---- src/Components/PixPaymentInput.res | 2 +- src/Components/SavedMethods.res | 2 +- src/Components/VpaIdPaymentInput.res | 2 +- src/LoaderController.res | 2 +- src/Payment.res | 14 ++++++++------ src/PaymentElement.res | 2 +- src/Payments/ACHBankDebit.res | 2 +- src/Payments/ACHBankTransfer.res | 2 +- src/Payments/AddBankDetails.res | 4 ++-- src/Payments/BacsBankDebit.res | 2 +- src/Payments/BacsBankTransfer.res | 2 +- src/Payments/BankTransfersPopup.res | 2 +- src/Payments/BecsBankDebit.res | 2 +- src/Payments/Boleto.res | 2 +- src/Payments/CardPayment.res | 2 +- src/Payments/DateOfBirth.res | 2 +- src/Payments/GPay.res | 2 +- src/Payments/KlarnaPayment.res | 2 +- src/Payments/PaymentMethodsWrapper.res | 2 +- src/Payments/PlaidSDKIframe.res | 2 +- src/Payments/PreMountLoader.res | 2 +- src/Payments/QRCodeDisplay.res | 2 +- src/Payments/SepaBankDebit.res | 2 +- src/Payments/SepaBankTransfer.res | 2 +- src/Payments/VoucherDisplay.res | 2 +- src/ThreeDSAuth.res | 2 +- src/ThreeDSMethod.res | 2 +- src/Utilities/ApplePayHelpers.res | 4 ++-- src/Utilities/DynamicFieldsUtils.res | 2 +- src/Utilities/GooglePayHelpers.res | 4 ++-- 37 files changed, 51 insertions(+), 48 deletions(-) diff --git a/src/Components/AddressPaymentInput.res b/src/Components/AddressPaymentInput.res index 0295888f6..6588dda36 100644 --- a/src/Components/AddressPaymentInput.res +++ b/src/Components/AddressPaymentInput.res @@ -141,7 +141,7 @@ let make = (~paymentType, ~className="") => { }, [country.value]) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { if line1.value == "" { diff --git a/src/Components/BillingNamePaymentInput.res b/src/Components/BillingNamePaymentInput.res index cf2d55a5d..a2af4033c 100644 --- a/src/Components/BillingNamePaymentInput.res +++ b/src/Components/BillingNamePaymentInput.res @@ -38,7 +38,7 @@ let make = (~paymentType, ~customFieldName=None, ~requiredFields as optionalRequ let nameRef = React.useRef(Nullable.null) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { if billingName.value == "" { diff --git a/src/Components/BlikCodePaymentInput.res b/src/Components/BlikCodePaymentInput.res index a4439b193..4650152b2 100644 --- a/src/Components/BlikCodePaymentInput.res +++ b/src/Components/BlikCodePaymentInput.res @@ -41,7 +41,7 @@ let make = () => { }, [blikCode.isValid]) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { if blikCode.value == "" { diff --git a/src/Components/EmailPaymentInput.res b/src/Components/EmailPaymentInput.res index 367f34468..a5b846dbf 100644 --- a/src/Components/EmailPaymentInput.res +++ b/src/Components/EmailPaymentInput.res @@ -41,7 +41,7 @@ let make = (~paymentType) => { }, [email.isValid]) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { if email.value == "" { diff --git a/src/Components/FullNamePaymentInput.res b/src/Components/FullNamePaymentInput.res index 04ad9df4c..a83708084 100644 --- a/src/Components/FullNamePaymentInput.res +++ b/src/Components/FullNamePaymentInput.res @@ -36,7 +36,7 @@ let make = (~paymentType, ~customFieldName=None, ~optionalRequiredFields=None) = let nameRef = React.useRef(Nullable.null) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { if fullName.value == "" { diff --git a/src/Components/FullScreenPortal.res b/src/Components/FullScreenPortal.res index 7f99f2bf0..89cb9cdb3 100644 --- a/src/Components/FullScreenPortal.res +++ b/src/Components/FullScreenPortal.res @@ -9,7 +9,7 @@ let make = (~children) => { React.useEffectOnEveryRender(() => { let handle = (ev: Window.event) => { try { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let dict = json->getDictFromJson if dict->Dict.get("fullScreenIframeMounted")->Option.isSome { diff --git a/src/Components/PaymentLoader.res b/src/Components/PaymentLoader.res index 88e75ff12..c8cb5fc55 100644 --- a/src/Components/PaymentLoader.res +++ b/src/Components/PaymentLoader.res @@ -1,13 +1,14 @@ @react.component let make = () => { + open Utils let (branding, setBranding) = React.useState(_ => "auto") React.useEffect0(() => { - Utils.handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)]) + handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)]) let handle = (ev: Window.event) => { - let json = ev.data->JSON.parseExn - let dict = json->Utils.getDictFromJson - setBranding(_ => dict->Utils.getDictFromDict("options")->Utils.getString("branding", "auto")) + let json = ev.data->safeParse + let dict = json->getDictFromJson + setBranding(_ => dict->getDictFromDict("options")->getString("branding", "auto")) } Window.addEventListener("message", handle) Some(() => {Window.removeEventListener("message", handle)}) diff --git a/src/Components/PixPaymentInput.res b/src/Components/PixPaymentInput.res index 27aab2774..8864a0c26 100644 --- a/src/Components/PixPaymentInput.res +++ b/src/Components/PixPaymentInput.res @@ -136,7 +136,7 @@ let make = (~label="") => { }, [pixCPF.value]) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { if pixKey.value == "" { diff --git a/src/Components/SavedMethods.res b/src/Components/SavedMethods.res index d2156005d..033fea60d 100644 --- a/src/Components/SavedMethods.res +++ b/src/Components/SavedMethods.res @@ -97,7 +97,7 @@ let make = ( ApplePayHelpers.useHandleApplePayResponse(~connectors=[], ~intent, ~isSavedMethodsFlow=true) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper let isCustomerAcceptanceRequired = customerMethod.recurringEnabled->not diff --git a/src/Components/VpaIdPaymentInput.res b/src/Components/VpaIdPaymentInput.res index 275ed7dc5..533145a84 100644 --- a/src/Components/VpaIdPaymentInput.res +++ b/src/Components/VpaIdPaymentInput.res @@ -33,7 +33,7 @@ let make = (~paymentType) => { } let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { if vpaId.value == "" { diff --git a/src/LoaderController.res b/src/LoaderController.res index 178e368d6..f74c76178 100644 --- a/src/LoaderController.res +++ b/src/LoaderController.res @@ -219,7 +219,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime open Promise let handleFun = (ev: Window.event) => { let json = try { - ev.data->JSON.parseExn + ev.data->safeParse } catch { | _ => Dict.make()->JSON.Encode.object } diff --git a/src/Payment.res b/src/Payment.res index f4281fe67..b4a75afc0 100644 --- a/src/Payment.res +++ b/src/Payment.res @@ -316,13 +316,14 @@ let make = (~paymentMode, ~integrateError, ~logger) => { }, [paymentMode]) React.useEffect0(() => { + open Utils let handleFun = (ev: Window.event) => { let json = try { - ev.data->JSON.parseExn + ev.data->safeParse } catch { | _ => Dict.make()->JSON.Encode.object } - let dict = json->Utils.getDictFromJson + let dict = json->getDictFromJson if dict->Dict.get("doBlur")->Option.isSome { logger.setLogInfo(~value="doBlur Triggered", ~eventName=BLUR, ()) setBlurState(_ => true) @@ -343,19 +344,20 @@ let make = (~paymentMode, ~integrateError, ~logger) => { setIsCVCValid(_ => None) } } - Utils.handleMessage(handleFun, "Error in parsing sent Data") + handleMessage(handleFun, "Error in parsing sent Data") }) React.useEffect(() => { + open Utils let handleDoSubmit = (ev: Window.event) => { - let json = ev.data->JSON.parseExn - let jsonDict = json->Utils.getDictFromJson + let json = ev.data->safeParse + let jsonDict = json->getDictFromJson let confirm = jsonDict->ConfirmType.itemToObjMapper if confirm.doSubmit { submitValue(ev, confirm.confirmParams) } } - Utils.handleMessage(handleDoSubmit, "") + handleMessage(handleDoSubmit, "") }, (cardNumber, cvcNumber, cardExpiry, isCVCValid, isExpiryValid, isCardValid)) React.useEffect(() => { diff --git a/src/PaymentElement.res b/src/PaymentElement.res index 99b21f7b3..947750d61 100644 --- a/src/PaymentElement.res +++ b/src/PaymentElement.res @@ -224,7 +224,7 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod cardsToRender(cardsContainerWidth) }, [cardsContainerWidth]) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit && selectedOption == "" { postFailedSubmitResponse(~errortype="validation_error", ~message="Select a payment method") diff --git a/src/Payments/ACHBankDebit.res b/src/Payments/ACHBankDebit.res index 596936bfe..73621ac9d 100644 --- a/src/Payments/ACHBankDebit.res +++ b/src/Payments/ACHBankDebit.res @@ -65,7 +65,7 @@ let make = (~paymentType: CardThemeType.mode) => { UtilityHooks.useHandlePostMessages(~complete, ~empty, ~paymentType="ach_bank_debit") let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { diff --git a/src/Payments/ACHBankTransfer.res b/src/Payments/ACHBankTransfer.res index 28ca94aa6..3eda9752f 100644 --- a/src/Payments/ACHBankTransfer.res +++ b/src/Payments/ACHBankTransfer.res @@ -23,7 +23,7 @@ let make = (~paymentType: CardThemeType.mode) => { }, [complete]) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { if complete { diff --git a/src/Payments/AddBankDetails.res b/src/Payments/AddBankDetails.res index fbbc13d51..ec6c02070 100644 --- a/src/Payments/AddBankDetails.res +++ b/src/Payments/AddBankDetails.res @@ -29,7 +29,7 @@ let make = (~paymentMethodType) => { React.useEffect0(() => { let onPlaidCallback = (ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let dict = json->Utils.getDictFromJson if dict->getBool("isPlaid", false) { let publicToken = dict->getDictFromDict("data")->getString("publicToken", "") @@ -64,7 +64,7 @@ let make = (~paymentMethodType) => { }) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { postFailedSubmitResponse( diff --git a/src/Payments/BacsBankDebit.res b/src/Payments/BacsBankDebit.res index 64b9ebc22..c4041bfb4 100644 --- a/src/Payments/BacsBankDebit.res +++ b/src/Payments/BacsBankDebit.res @@ -83,7 +83,7 @@ let make = (~paymentType: CardThemeType.mode) => { }, [complete]) let submitCallback = (ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { diff --git a/src/Payments/BacsBankTransfer.res b/src/Payments/BacsBankTransfer.res index c22e5ce8a..6dabf9f0c 100644 --- a/src/Payments/BacsBankTransfer.res +++ b/src/Payments/BacsBankTransfer.res @@ -24,7 +24,7 @@ let default = (~paymentType: CardThemeType.mode) => { }, [complete]) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { if complete { diff --git a/src/Payments/BankTransfersPopup.res b/src/Payments/BankTransfersPopup.res index bc0ed57c2..23561daec 100644 --- a/src/Payments/BankTransfersPopup.res +++ b/src/Payments/BankTransfersPopup.res @@ -50,7 +50,7 @@ let make = (~transferType) => { React.useEffect0(() => { handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)]) let handle = (ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let dict = json->Utils.getDictFromJson if dict->Dict.get("fullScreenIframeMounted")->Option.isSome { let metadata = dict->getJsonObjectFromDict("metadata") diff --git a/src/Payments/BecsBankDebit.res b/src/Payments/BecsBankDebit.res index e85faa5b8..42001bc95 100644 --- a/src/Payments/BecsBankDebit.res +++ b/src/Payments/BecsBankDebit.res @@ -52,7 +52,7 @@ let make = (~paymentType: CardThemeType.mode) => { }, [complete]) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { if complete { diff --git a/src/Payments/Boleto.res b/src/Payments/Boleto.res index 1e5104c4d..9252f65ac 100644 --- a/src/Payments/Boleto.res +++ b/src/Payments/Boleto.res @@ -51,7 +51,7 @@ let make = (~paymentType: CardThemeType.mode) => { }, [complete]) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { diff --git a/src/Payments/CardPayment.res b/src/Payments/CardPayment.res index 9d4934d06..555a22434 100644 --- a/src/Payments/CardPayment.res +++ b/src/Payments/CardPayment.res @@ -129,7 +129,7 @@ let make = ( ) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper let (month, year) = CardUtils.getExpiryDates(cardExpiry) diff --git a/src/Payments/DateOfBirth.res b/src/Payments/DateOfBirth.res index c718d3db4..d5c9272d7 100644 --- a/src/Payments/DateOfBirth.res +++ b/src/Payments/DateOfBirth.res @@ -28,7 +28,7 @@ let make = () => { let (isNotEligible, setIsNotEligible) = React.useState(_ => false) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { switch selectedDate->Nullable.toOption { diff --git a/src/Payments/GPay.res b/src/Payments/GPay.res index 82e8d4e6a..8e4b867d6 100644 --- a/src/Payments/GPay.res +++ b/src/Payments/GPay.res @@ -185,7 +185,7 @@ let make = ( React.useEffect0(() => { let handleGooglePayMessages = (ev: Window.event) => { let json = try { - ev.data->JSON.parseExn + ev.data->safeParse } catch { | _ => Dict.make()->JSON.Encode.object } diff --git a/src/Payments/KlarnaPayment.res b/src/Payments/KlarnaPayment.res index e2f7027fe..eab20ea75 100644 --- a/src/Payments/KlarnaPayment.res +++ b/src/Payments/KlarnaPayment.res @@ -42,7 +42,7 @@ let make = (~paymentType) => { }, [complete]) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper let (connectors, _) = paymentMethodListValue->PaymentUtils.getConnectors(PayLater(Klarna(Redirect))) diff --git a/src/Payments/PaymentMethodsWrapper.res b/src/Payments/PaymentMethodsWrapper.res index bf3d939bd..9d3c02f57 100644 --- a/src/Payments/PaymentMethodsWrapper.res +++ b/src/Payments/PaymentMethodsWrapper.res @@ -56,7 +56,7 @@ let make = (~paymentType: CardThemeType.mode, ~paymentMethodName: string) => { ) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { if complete { diff --git a/src/Payments/PlaidSDKIframe.res b/src/Payments/PlaidSDKIframe.res index e557efe58..370129124 100644 --- a/src/Payments/PlaidSDKIframe.res +++ b/src/Payments/PlaidSDKIframe.res @@ -18,7 +18,7 @@ let make = () => { React.useEffect0(() => { let handle = (ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let metaData = json->getDictFromJson->getDictFromDict("metadata") let linkToken = metaData->getString("linkToken", "") if linkToken->String.length > 0 { diff --git a/src/Payments/PreMountLoader.res b/src/Payments/PreMountLoader.res index 36361c4f9..d869c2dd5 100644 --- a/src/Payments/PreMountLoader.res +++ b/src/Payments/PreMountLoader.res @@ -112,7 +112,7 @@ let make = ( let handle = (ev: Window.event) => { let json = try { - ev.data->JSON.parseExn + ev.data->safeParse } catch { | _ => JSON.Encode.null } diff --git a/src/Payments/QRCodeDisplay.res b/src/Payments/QRCodeDisplay.res index c91ddd1b0..dbcadd077 100644 --- a/src/Payments/QRCodeDisplay.res +++ b/src/Payments/QRCodeDisplay.res @@ -21,7 +21,7 @@ let make = () => { React.useEffect0(() => { handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)]) let handle = (ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let dict = json->Utils.getDictFromJson if dict->Dict.get("fullScreenIframeMounted")->Option.isSome { let metadata = dict->getJsonObjectFromDict("metadata") diff --git a/src/Payments/SepaBankDebit.res b/src/Payments/SepaBankDebit.res index 9a279c816..10c21a76c 100644 --- a/src/Payments/SepaBankDebit.res +++ b/src/Payments/SepaBankDebit.res @@ -59,7 +59,7 @@ let make = (~paymentType: CardThemeType.mode) => { }, [complete]) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { diff --git a/src/Payments/SepaBankTransfer.res b/src/Payments/SepaBankTransfer.res index a13f9e6f2..b028a1497 100644 --- a/src/Payments/SepaBankTransfer.res +++ b/src/Payments/SepaBankTransfer.res @@ -34,7 +34,7 @@ let make = (~paymentType) => { }, [complete]) let submitCallback = React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { if complete { diff --git a/src/Payments/VoucherDisplay.res b/src/Payments/VoucherDisplay.res index b65369ead..072ff80fa 100644 --- a/src/Payments/VoucherDisplay.res +++ b/src/Payments/VoucherDisplay.res @@ -23,7 +23,7 @@ let make = () => { React.useEffect0(() => { handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)]) let handle = (ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let dict = json->Utils.getDictFromJson if dict->Dict.get("fullScreenIframeMounted")->Option.isSome { let metadata = dict->getJsonObjectFromDict("metadata") diff --git a/src/ThreeDSAuth.res b/src/ThreeDSAuth.res index 2ba9db986..980231676 100644 --- a/src/ThreeDSAuth.res +++ b/src/ThreeDSAuth.res @@ -24,7 +24,7 @@ let make = () => { React.useEffect0(() => { handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)]) let handle = (ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let dict = json->getDictFromJson if dict->Dict.get("fullScreenIframeMounted")->Option.isSome { let metadata = dict->getJsonObjectFromDict("metadata") diff --git a/src/ThreeDSMethod.res b/src/ThreeDSMethod.res index 6edf11412..9187bcc8f 100644 --- a/src/ThreeDSMethod.res +++ b/src/ThreeDSMethod.res @@ -58,7 +58,7 @@ let make = () => { React.useEffect0(() => { handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)]) let handle = (ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let dict = json->Utils.getDictFromJson if dict->Dict.get("fullScreenIframeMounted")->Option.isSome { let metadata = dict->getJsonObjectFromDict("metadata") diff --git a/src/Utilities/ApplePayHelpers.res b/src/Utilities/ApplePayHelpers.res index 667b39682..308d9bd07 100644 --- a/src/Utilities/ApplePayHelpers.res +++ b/src/Utilities/ApplePayHelpers.res @@ -165,7 +165,7 @@ let useHandleApplePayResponse = ( React.useEffect(() => { let handleApplePayMessages = (ev: Window.event) => { let json = try { - ev.data->JSON.parseExn + ev.data->safeParse } catch { | _ => Dict.make()->JSON.Encode.object } @@ -255,7 +255,7 @@ let useSubmitCallback = (~isWallet, ~sessionObj, ~componentName) => { React.useCallback((ev: Window.event) => { if !isWallet { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit && areRequiredFieldsValid && !areRequiredFieldsEmpty { options.readOnly ? () : handleApplePayButtonClicked(~sessionObj, ~componentName) diff --git a/src/Utilities/DynamicFieldsUtils.res b/src/Utilities/DynamicFieldsUtils.res index 35dee4224..5b4f31ea8 100644 --- a/src/Utilities/DynamicFieldsUtils.res +++ b/src/Utilities/DynamicFieldsUtils.res @@ -770,7 +770,7 @@ let useSubmitCallback = () => { let {localeString} = Recoil.useRecoilValueFromAtom(configAtom) React.useCallback((ev: Window.event) => { - let json = ev.data->JSON.parseExn + let json = ev.data->Utils.safeParse let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { if line1.value == "" { diff --git a/src/Utilities/GooglePayHelpers.res b/src/Utilities/GooglePayHelpers.res index b8bb45ab2..f43066cd5 100644 --- a/src/Utilities/GooglePayHelpers.res +++ b/src/Utilities/GooglePayHelpers.res @@ -108,7 +108,7 @@ let useHandleGooglePayResponse = ( React.useEffect(() => { let handle = (ev: Window.event) => { let json = try { - ev.data->JSON.parseExn + ev.data->safeParse } catch { | _ => Dict.make()->JSON.Encode.object } @@ -180,7 +180,7 @@ let useSubmitCallback = (~isWallet, ~sessionObj, ~componentName) => { React.useCallback((ev: Window.event) => { if !isWallet { - let json = ev.data->JSON.parseExn + let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit && areRequiredFieldsValid && !areRequiredFieldsEmpty { handleGooglePayClicked(~sessionObj, ~componentName, ~iframeId, ~readOnly=options.readOnly)