Tech
01/05/2023, 8:12 PMKristian Nedrevold
01/05/2023, 8:44 PMKristian Nedrevold
01/05/2023, 8:51 PMsuspend inline fun <reified T>PipelineContext<Unit, ApplicationCall>.receiveCatching(): Result<T> = try {
Result.success(call.receive())
} catch (e: Exception) {
Result.failure(e)
}
Tech
01/05/2023, 8:51 PMTech
01/05/2023, 8:52 PM@Resource("test") @Serializable
class Resource(
val e: RandomEnum
)
enum class RandomEnum {
Test
}
Tech
01/05/2023, 8:52 PMlocalhost:8080//test?e=Test
that worksTech
01/05/2023, 8:53 PMKristian Nedrevold
01/05/2023, 9:03 PMsuspend inline fun <reified T>PipelineContext<Unit, ApplicationCall>.receiveCatching(): Result<T> = try {
Result.success(call.receive())
} catch (e: Exception) {
Result.failure(e)
}
inline fun <reified R : Any> Route.postCatching(
crossinline body: suspend PipelineContext<Unit, ApplicationCall>.(Result<R>) -> Unit
): Route = postCatching {
body(receiveCatching<R>())
}
fun Route.postCatching(body: PipelineInterceptor<Unit, ApplicationCall>): Route {
return method(<http://HttpMethod.Post|HttpMethod.Post>) { handle(body) }
}
Kristian Nedrevold
01/05/2023, 9:03 PMKristian Nedrevold
01/05/2023, 9:04 PMTech
01/05/2023, 9:04 PM