Skip to content

Commit

Permalink
Logging exceptions for API call errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrishab Srivatsa committed Sep 16, 2023
1 parent 5ef3db4 commit cae559d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 40 deletions.
39 changes: 9 additions & 30 deletions src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,8 @@ let intentCall = (
resolve()
})
->catch(err => {
let exceptionJson =
err
->Js.Exn.asJsExn
->Belt.Option.flatMap(Js.Exn.message)
->Belt.Option.flatMap(OrcaUtils.safeParseOpt)
->Belt.Option.getWithDefault(Js.Json.null)
let exceptionJson = err->toJson

logApi(
~optLogger,
~url=uri,
Expand Down Expand Up @@ -357,12 +353,7 @@ let intentCall = (
let url = urlSearch(confirmParam.return_url)
url.searchParams.set(. "payment_intent_client_secret", clientSecret)
url.searchParams.set(. "status", "failed")
let exceptionJson =
err
->Js.Exn.asJsExn
->Belt.Option.flatMap(Js.Exn.message)
->Belt.Option.flatMap(OrcaUtils.safeParseOpt)
->Belt.Option.getWithDefault(Js.Json.null)
let exceptionJson = err->toJson
logApi(
~optLogger,
~url=uri,
Expand Down Expand Up @@ -672,12 +663,8 @@ let useSessions = (
json->resolve
})
->catch(err => {
let exceptionJson =
err
->Js.Exn.asJsExn
->Belt.Option.flatMap(Js.Exn.message)
->Belt.Option.flatMap(OrcaUtils.safeParseOpt)
->Belt.Option.getWithDefault(Js.Json.null)
let exceptionJson = err->toJson

logApi(
~optLogger,
~url=uri,
Expand Down Expand Up @@ -746,12 +733,8 @@ let usePaymentMethodList = (~clientSecret, ~publishableKey, ~logger) => {
json->resolve
})
->catch(err => {
let exceptionJson =
err
->Js.Exn.asJsExn
->Belt.Option.flatMap(Js.Exn.message)
->Belt.Option.flatMap(OrcaUtils.safeParseOpt)
->Belt.Option.getWithDefault(Js.Json.null)
let exceptionJson = err->toJson

logApi(
~optLogger=Some(logger),
~url=uri,
Expand Down Expand Up @@ -817,12 +800,8 @@ let useCustomerDetails = (~clientSecret, ~publishableKey, ~optLogger) => {
})
->then(res => resolve(res))
->catch(err => {
let exceptionJson =
err
->Js.Exn.asJsExn
->Belt.Option.flatMap(Js.Exn.message)
->Belt.Option.flatMap(OrcaUtils.safeParseOpt)
->Belt.Option.getWithDefault(Js.Json.null)
let exceptionJson = err->toJson

logApi(
~optLogger,
~url=uri,
Expand Down
13 changes: 3 additions & 10 deletions src/orca-loader/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,7 @@ let make = (
resolve()
})
->catch(err => {
let exceptionMessage =
err
->Js.Exn.asJsExn
->Belt.Option.flatMap(Js.Exn.message)
->Belt.Option.getWithDefault("TrustPay GooglePay Error")
let exceptionMessage = err->toJson->Js.Json.stringify
logger.setLogInfo(
~value=exceptionMessage,
~eventName=GOOGLE_PAY_FLOW,
Expand Down Expand Up @@ -465,11 +461,8 @@ let make = (
resolve()
})
->catch(err => {
let exceptionMessage =
err
->Js.Exn.asJsExn
->Belt.Option.flatMap(Js.Exn.message)
->Belt.Option.getWithDefault("TrustPay ApplePay Error")
let exceptionMessage = err->toJson->Js.Json.stringify

logger.setLogInfo(
~eventName=APPLE_PAY_FLOW,
~paymentMethod="APPLE_PAY",
Expand Down

0 comments on commit cae559d

Please sign in to comment.