Emil Kantis
12/05/2023, 8:21 AMJakub Zalas
12/05/2023, 9:53 AMJakub Zalas
12/05/2023, 9:55 AMEmil Kantis
12/05/2023, 9:56 AMCLOVIS
12/05/2023, 1:05 PMsimon.vergauwen
12/05/2023, 5:22 PMDo you try to model any/every possible error that can occur (like connection issues, etc), or just those related to the domain?Only those related to the domain.
UserAlreadyExists
(unique violations), InvalidPassword
, validations from incoming request, etc.
https://github.com/nomisRev/ktor-arrow-example/blob/main/src/main/kotlin/io/github/nomisrev/DomainError.ktBen
12/05/2023, 5:27 PMDomainError
into resource specific groups (or something else) or do you just keep growing the DomainError
file?simon.vergauwen
12/05/2023, 5:40 PMDomainError.kt
and split it more into logical groups. Wether that is resource specific, or domain specific, use-case, etc is also a bit subjective.
I did already split it in my example project, but they're still defined in the same file. The hierarchy is defined as a tree, so it already has sub hierarchies which could be moved into their own files.Jakub Zalas
12/05/2023, 5:48 PMsimon.vergauwen
12/05/2023, 5:59 PMsealed class Parent
sealed class SubA : Parent
object ErrorA : SubA
sealed class SubB : Parent
object ErrorB: SubB
fun a(): Either<ErrorA, Int> = TODO()
fun b(): Either<ErrorB, Int> = TODO()
either<Parent, Int> {
a() + b()
}
Otherwise:
object OtherError
sealed class SubA
object ErrorA : SubA
sealed class SubB
object ErrorB: SubB
fun a(): Either<ErrorA, Int> = TODO()
fun b(): Either<ErrorB, Int> = TODO()
either<OtherError, Int> {
val a = recover({ a() }) { OtherError }
val b = recover({ b() }) { OtherError }
a + b
}
CLOVIS
12/05/2023, 6:03 PMCLOVIS
12/05/2023, 6:05 PMraise(404)
so you can mapErrors
from your domain to the HTTP API (and back on the other side). I had a prototype of it last year but I wasn't happy with it.