Srki Rakic
02/15/2022, 5:02 PMsuspend because it is making a network call (not pure), but I'm curious what would be the recommended approach to handling exceptions.raulraja
02/15/2022, 5:04 PMEither.catch { } then toValidatedNelraulraja
02/15/2022, 5:04 PMraulraja
02/15/2022, 5:06 PMdata class InvalidDue2Network(t: Throwable): YourBaseError()raulraja
02/15/2022, 5:07 PMSrki Rakic
02/15/2022, 6:26 PMEither.catch { }.mapLeft { } , but seeing the example I was wondering if that is not the best/recommended pattern for handling functions with side-effects.simon.vergauwen
02/17/2022, 10:22 AMEither.catch { }.mapLeft { } is a great pattern to use. Typically you want to make sure that your error type keeps a reference to the Throwable so you have that information for later inspection.
Something like:
data class DatabaseError(val original: Throwable)
val user: Eithre<Throwable, User> =
Either.catch {
userFromDatabase()
}.mapLeft(::DatabaseError)Srki Rakic
02/25/2022, 12:12 AM