George
06/08/2022, 11:56 AMoverride fun handle(exchange: ServerWebExchange, ex: Throwable): Mono<Void> = mono {
val mono = when (ex) {
is DataBufferLimitException -> {
exchange.response.let {
it.statusCode = HttpStatus.BAD_REQUEST
it.headers.contentType = MediaType.APPLICATION_JSON
val responseBody = it.bufferFactory()
.wrap("""{"message":"file larger than 100 MB"}""".encodeToByteArray())
it.writeWith(Mono.just(responseBody))
}
}
// default spring error response
else -> Mono.error(ex)
}
mono.awaitSingle()
}
On the other hand, if the contract is indeed more complex/time-consuming do i gain a non-trivial advantage if i use coroutines?
I leave the option of needing to call another suspending fuinction out, because then it is mandatory to be in the coroutines world.