In Spine 0.9.0, you can type-safely declare HTTP f...
# arrow
c
In Spine 0.9.0, you can type-safely declare HTTP failures in common code with full
Raise
compatibility:
Copy code
// Common

val createUser by post()
    .request<UserCreationDto>()
    .response<User>()
    .failure<NotAllowedToCreateUser>(HttpStatusCode.UnprocessableEntity)
    .failure<Unit>(HttpStatusCode.Unauthorized)
    .failure<UserAlreadyExists>(HttpStatusCode.Conflict)

// Server

routeWithRaise(createUser) {
    ensure(!userService.exists(body.email)) { UserAlreadyExists(body.email) }
    
    val created = withError({ NotAllowedToCreateUser(it.email) }) { 
        userService.createUser(body)
    }

    respond(created)
}

// Client

context(_: Raise<NotAllowedToCreateUser>, _: Raise<UserAlreadyExists>)
fun HttpClient.createUser(email: String) =
    recover<Unit, User>(
        block = { request(createUser, UserCreationDto(email)).body() },
        recover = { error("Shouldn't call createUser before authenticating") }
    )
https://spine.opensavvy.dev/failures-arrow.html • #C078Z1QRHL3
arrow intensifies 3
kodee loving 3