Skip to content

Commit

Permalink
fix: format function refactor for better logs readability
Browse files Browse the repository at this point in the history
  • Loading branch information
PritishBudhiraja committed Oct 29, 2024
1 parent 1ff5e17 commit 789639f
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/Utilities/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ let getInt = (dict, key, default: int) => {
->Float.toInt
}

let getJsonFromArrayOfJson = arr => arr->Dict.fromArray->JSON.Encode.object

let getFloatFromString = (str, default) => str->Float.fromString->Option.getOr(default)

let getFloatFromJson = (json, default) => {
Expand Down Expand Up @@ -864,9 +866,11 @@ let fetchApi = (uri, ~bodyStr: string="", ~headers=Dict.make(), ~method: Fetch.m
},
)
->catch(err => {
Js.log2("errerrerrerrerrerrerr", err)
reject(err)
})
->then(resp => {
Js.log2("resprespresprespresp", resp)
resolve(resp)
})
})
Expand All @@ -877,9 +881,29 @@ let arrayJsonToCamelCase = arr => {
item->transformKeys(CamelCase)
})
}
let formatException = exc => {
exc->Identity.anyTypeToJson
}

let formatException = exc =>
switch exc {
| Exn.Error(obj) =>
let (message, name, stack, fileName) = (
Exn.message(obj),
Exn.name(obj),
Exn.stack(obj),
Exn.fileName(obj),
)
[
("message", message->Identity.anyTypeToJson),
("type", name->Identity.anyTypeToJson),
("stack", stack->Identity.anyTypeToJson),
("fileName", fileName->Identity.anyTypeToJson),
]
| _ => [
("message", "Unknown error"->Identity.anyTypeToJson),
("type", "Unknown"->Identity.anyTypeToJson),
("stack", "Unknown"->Identity.anyTypeToJson),
("fileName", "Unknown"->Identity.anyTypeToJson),
]
}->getJsonFromArrayOfJson

let getArrayValFromJsonDict = (dict, key, arrayKey) => {
dict
Expand Down Expand Up @@ -1300,8 +1324,6 @@ let getIsWalletElementPaymentType = (paymentType: CardThemeType.mode) => {

let getUniqueArray = arr => arr->Array.map(item => (item, ""))->Dict.fromArray->Dict.keysToArray

let getJsonFromArrayOfJson = arr => arr->Dict.fromArray->JSON.Encode.object

let getStateNameFromStateCodeAndCountry = (list: JSON.t, stateCode: string, country: string) => {
let options =
list
Expand Down

0 comments on commit 789639f

Please sign in to comment.