Hi, added Detekt to my project and it spotted some...
# ktor
m
Hi, added Detekt to my project and it spotted some error with this code (although I'm not happy with it either):
Copy code
suspend fun getBlockDetailsByHeight(blockDetailsByHeightRequest: BlockDetailsByHeightRequest): BlockDetail? {
        val jsonBody = Json.encodeToString(blockDetailsByHeightRequest)

        val builder = HttpRequestBuilder().apply {
            method = <http://HttpMethod.Post|HttpMethod.Post>
            node.ssl.let {
                if (it) {
                    url.takeFrom("https://${node.hostName}:${node.port}/get_block_details_by_height")
                } else {
                    url.takeFrom("http://${node.hostName}:${node.port}/get_block_details_by_height")
                }
            }
            contentType(ContentType.Application.Json)
            headers {
                append("Content-Length", jsonBody.length.toString())
            }
            setBody(jsonBody)
        }

        try {
            return <http://client.post|client.post>(builder).body<BlockDetail>()
        } catch (e: Exception) {
            logger.error("Error getting block details by height", e)
        }

        return null
    }
It complains about exception being to generic. Which is true. But what kind of exception(s) should I try to catch here? I'm trying to figure out by checking the client.post or client.get functions, but I can't seem to find what will be throwned. Any idea?
c
we catch
JsonConvertException
,
UnresolvedAddressException
, and
ClientRequestException
s
Exception
also captures
CancellationException
which can be problematic for structured concurrency
💯 1