commit 6e2bf1a4b94a2ca07429a816e4059ef538240af0 parent 2a73485b7e642fa0d6e14c6d50398da92ba49145 Author: MS <ms@taler.net> Date: Tue, 26 Sep 2023 21:47:30 +0200 Decompression error handling. Diffstat:
| M | bank/src/main/kotlin/tech/libeufin/bank/Main.kt | | | 19 | ++++++++++++++----- |
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt @@ -181,11 +181,20 @@ val corebankDecompressionPlugin = createApplicationPlugin("RequestingBodyDecompr onCallReceive { call -> transformBody { data -> if (call.request.headers[HttpHeaders.ContentEncoding] == "deflate") { - val brc = withContext(Dispatchers.IO) { - val inflated = InflaterInputStream(data.toInputStream()) - @Suppress("BlockingMethodInNonBlockingContext") - val bytes = inflated.readAllBytes() - ByteReadChannel(bytes) + val brc = try { + withContext(Dispatchers.IO) { + val inflated = InflaterInputStream(data.toInputStream()) + + @Suppress("BlockingMethodInNonBlockingContext") + val bytes = inflated.readAllBytes() + ByteReadChannel(bytes) + } + } catch (e: Exception) { + logger.error("Deflated request failed to inflate: ${e.message}") + throw badRequest( + hint = "Could not inflate request", + talerErrorCode = TalerErrorCode.TALER_EC_END // FIXME: provide dedicated EC. + ) } brc } else data