Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error utils refactor #405

Merged
merged 3 commits into from
May 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading