dave08
03/26/2019, 2:07 PMpeek
is not really made for this...:
override suspend fun convertForReceive(context: PipelineContext<ApplicationReceiveRequest, ApplicationCall>): Any? = withContext(
<http://Dispatchers.IO|Dispatchers.IO>) {
val request = context.subject
val channel = request.value as? ByteReadChannel ?: return@withContext null
val reader = channel.toInputStream().source().buffer()
val buffer2 = reader.peek()
val type = request.type
return@withContext moshi.adapter<Any>(type.java).runCatching {
fromJson(reader)
}.onFailure {
logger.error(it) { "Error converting request body <${type.simpleName}>: ${buffer2.readUtf8()}" }
}.getOrThrow()
}