Skip to content

Commit

Permalink
refactor: clean up; use curried function
Browse files Browse the repository at this point in the history
  • Loading branch information
seekshiva committed Sep 13, 2024
1 parent f9e27c1 commit f2eb3d1
Showing 1 changed file with 12 additions and 36 deletions.
48 changes: 12 additions & 36 deletions src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -1991,14 +1991,15 @@ let calculateTax = (
("shipping", shippingAddress),
("payment_method_type", paymentMethodType),
]
logApi(
~optLogger=Some(logger),
~url=uri,
~apiLogType=Request,
~eventName=EXTERNAL_TAX_CALCULATION,
~logType=INFO,
~logCategory=API,
)
let logApiData =
logApi(
~optLogger=Some(logger),
~url=uri,
~eventName=EXTERNAL_TAX_CALCULATION,
~logCategory=API,
...
)
logApiData(~apiLogType=Request, ~logType=INFO)
fetchApi(
uri,
~method=#POST,
Expand All @@ -2011,42 +2012,17 @@ let calculateTax = (
resp
->Fetch.Response.json
->then(data => {
logApi(
~optLogger=Some(logger),
~url=uri,
~data,
~statusCode,
~apiLogType=Err,
~eventName=EXTERNAL_TAX_CALCULATION,
~logType=ERROR,
~logCategory=API,
)
logApiData(~data, ~statusCode, ~apiLogType=Err, ~logType=ERROR)
JSON.Encode.null->resolve
})
} else {
logApi(
~optLogger=Some(logger),
~url=uri,
~statusCode,
~apiLogType=Response,
~eventName=EXTERNAL_TAX_CALCULATION,
~logType=INFO,
~logCategory=API,
)
logApiData(~statusCode, ~apiLogType=Response, ~logType=INFO)
resp->Fetch.Response.json
}
})
->catch(err => {
let exceptionMessage = err->formatException
logApi(
~optLogger=Some(logger),
~url=uri,
~apiLogType=NoResponse,
~eventName=EXTERNAL_TAX_CALCULATION,
~logType=ERROR,
~logCategory=API,
~data=exceptionMessage,
)
logApiData(~apiLogType=NoResponse, ~logType=ERROR, ~data=exceptionMessage)
JSON.Encode.null->resolve
})
}

0 comments on commit f2eb3d1

Please sign in to comment.