Not necessarily a Ktor question, but I'm getting a...
# ktor
l
Not necessarily a Ktor question, but I'm getting an error that
suspend function can only be called from a coroutine
when I try using Arrow's Either.fold inside of `post {...}`:
Copy code
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 :|
a
The compilator is able to compile the following code:
Copy code
data 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)
                }
            )
    }
}
l
doh! wow, thank you @Aleksei Tirman [JB] Really appreciate the reply, as always