Levi
12/13/2023, 2:29 PMsuspend function can only be called from a coroutine
when I try using Arrow's Either.fold inside of `post {...}`:
fun Route.doTheThing(client: Client) {
post() {
Either.catchOrThrow<Exception, DoTheThingRequestBody> {
call.receive<DoTheThingRequestBody>()
}
.fold(
{ call.respond(HttpStatusCode.BadRequest, "Invalid email") },
{
val response = client.doThing(it.email)
call.respondText(response.bodyAsText(), ContentType.Application.Json, response.status)
}
)
}
}
Compiler doesn't like the call.Respond...
calls. Do I need to somehow use an explicit receiver to disambiguate? Can't seem to figure this out :|Aleksei Tirman [JB]
12/14/2023, 7:31 AMdata class DoTheThingRequestBody(val x: Int)
fun Route.doTheThing(client: HttpClient) {
post {
Either.catchOrThrow<Exception, DoTheThingRequestBody> {
call.receive<DoTheThingRequestBody>()
}
.fold(
{ call.respond(HttpStatusCode.BadRequest, "Invalid email") },
{
val response = client.get("")
call.respondText(response.bodyAsText(), ContentType.Application.Json, response.status)
}
)
}
}
Levi
12/15/2023, 5:01 PM