Refactor and Improve Type Safety in Error Handling Logic

return Match.value(error).pipe(
  Match.whenOr(
    (err: unknown) => ErrorUtility.isInternalError()(err) && (log.includes('internal_error') || log.includes('all')),
    (err: unknown) => ErrorUtility.isException()(err) && (log.includes('known_exception') || log.includes('all')),
    err => {},
  ),
  Match.when(
    (err: unknown) => err instanceof Exception && (log.includes('adonis_exception') || log.includes('all')),
    err => {},
  ),
  Match.when(
    (err: unknown) => (log.includes('unknown') || log.includes('all')) && (!ErrorUtility.isInternalError()(err) && !ErrorUtility.isException()(err) && !(err instanceof Exception)),
    err => {},
  ),
  Match.orElse(() => Effect.void),
)


is there any better way to do this? and still have type safety? right now, the err is unknown even after predicate since there is addition of log.includes. and can we make it more strucutred and organized?
Was this page helpful?