From 65c736cc23dcbaea3e41c9e76fd66d12c59713ef Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sun, 2 May 2021 14:13:12 -0700 Subject: [PATCH] Improved excepetions handling. --- config/detekt/baseline.xml | 16 +++++++--------- .../net/thauvin/erik/pinboard/PinboardPoster.kt | 5 ++++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/config/detekt/baseline.xml b/config/detekt/baseline.xml index 23161d0..8b70a46 100644 --- a/config/detekt/baseline.xml +++ b/config/detekt/baseline.xml @@ -1,11 +1,9 @@ - + - - - ComplexMethod:PinboardPoster.kt$PinboardPoster$private fun executeMethod(method: String, params: List<Pair<String, String>>): Boolean + + LongParameterList:PinboardPoster.kt$PinboardPoster$( url: String, description: String, extended: String = "", tags: String = "", dt: String = "", replace: Boolean = true, shared: Boolean = true, toRead: Boolean = false ) - NestedBlockDepth:PinboardPoster.kt$PinboardPoster$private fun executeMethod(method: String, params: List<Pair<String, String>>): Boolean - ThrowsCount:PinboardPoster.kt$PinboardPoster$internal fun parseMethodResponse(method: String, response: String) - TooGenericExceptionCaught:PinboardPoster.kt$PinboardPoster$e: Exception - - \ No newline at end of file + NestedBlockDepth:PinboardPoster.kt$PinboardPoster$private fun executeMethod(method: String, params: List<Pair<String, String>>): Boolean + ThrowsCount:PinboardPoster.kt$PinboardPoster$@Throws(IOException::class) internal fun parseMethodResponse(method: String, response: String) + + diff --git a/src/main/kotlin/net/thauvin/erik/pinboard/PinboardPoster.kt b/src/main/kotlin/net/thauvin/erik/pinboard/PinboardPoster.kt index ef2a864..d309c73 100644 --- a/src/main/kotlin/net/thauvin/erik/pinboard/PinboardPoster.kt +++ b/src/main/kotlin/net/thauvin/erik/pinboard/PinboardPoster.kt @@ -205,6 +205,7 @@ open class PinboardPoster() { return false } + @Throws(IOException::class) internal fun parseMethodResponse(method: String, response: String) { val factory = DocumentBuilderFactory.newInstance().apply { isValidating = false @@ -228,8 +229,10 @@ open class PinboardPoster() { } else { throw IOException("An error has occurred while executing $method.") } - } catch (e: Exception) { + } catch (e: org.xml.sax.SAXException) { throw IOException("Could not parse $method response.", e) + } catch (e: IllegalArgumentException) { + throw IOException("Invalid input source for $method response", e) } }