Skip to content

Commit

Permalink
fix: error utils refactor (#405)
Browse files Browse the repository at this point in the history
Co-authored-by: Pritish Budhiraja <[email protected]>
Co-authored-by: Shiva Nandan <[email protected]>
  • Loading branch information
3 people authored May 31, 2024
1 parent 9c6a87c commit 8d833e4
Showing 1 changed file with 19 additions and 43 deletions.
62 changes: 19 additions & 43 deletions src/Utilities/ErrorUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -112,51 +112,27 @@ let manageErrorWarning = (
~logger: OrcaLogger.loggerMake,
(),
) => {
let entry = errorWarning->Array.find(((value, _, _)) => {
value == key
})
let entry = errorWarning->Array.find(((value, _, _)) => value == key)
switch entry {
| Some(value) => {
let (key, type_, str) = value
switch (type_, str) {
| (Error, Static(string)) =>
logger.setLogError(
~value=string,
~eventName=key,
~logType=ERROR,
~logCategory=USER_ERROR,
(),
)
Console.error(string)
Exn.raiseError(string)
| (Warning, Static(string)) =>
logger.setLogError(
~value=string,
~eventName=key,
~logType=WARNING,
~logCategory=USER_ERROR,
(),
)
Console.warn(string)
| (Error, Dynamic(fn)) =>
logger.setLogError(
~value=fn(dynamicStr),
~eventName=key,
~logType=ERROR,
~logCategory=USER_ERROR,
(),
)
Console.error(fn(dynamicStr))
Exn.raiseError(fn(dynamicStr))
| (Warning, Dynamic(fn)) =>
logger.setLogError(
~value=fn(dynamicStr),
~eventName=key,
~logType=WARNING,
~logCategory=USER_ERROR,
(),
)
Console.warn(fn(dynamicStr))
let (eventName, type_, str) = value

let value = switch str {
| Static(string) => string
| Dynamic(fn) => fn(dynamicStr)
}
let logType: OrcaLogger.logType = switch type_ {
| Warning => WARNING
| Error => ERROR
}

logger.setLogError(~value, ~eventName, ~logType, ~logCategory=USER_ERROR, ())

switch type_ {
| Warning => Console.warn(value)
| Error =>
Console.error(value)
Exn.raiseError(value)
}
}
| None => ()
Expand Down

0 comments on commit 8d833e4

Please sign in to comment.