From 1bc653db3bd21142c5aa113be8a3521d9dc8d38f Mon Sep 17 00:00:00 2001 From: dalbodeule <11470513+dalbodeule@users.noreply.github.com> Date: Fri, 7 Jun 2024 11:34:28 +0900 Subject: [PATCH] fix pdns api clients (retry 13x) --- .../space/mori/dnsapi/PowerDNSAPIClient.kt | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/space/mori/dnsapi/PowerDNSAPIClient.kt b/src/main/kotlin/space/mori/dnsapi/PowerDNSAPIClient.kt index 5a86460..24da999 100644 --- a/src/main/kotlin/space/mori/dnsapi/PowerDNSAPIClient.kt +++ b/src/main/kotlin/space/mori/dnsapi/PowerDNSAPIClient.kt @@ -23,6 +23,7 @@ class PowerDNSAPIClient() { private val gson = Gson() private val client = OkHttpClient() + @Throws(PowerDNSAPIError::class) fun createZone(zoneName: String): Response { val body = gson.toJson(mapOf( "name" to zoneName, @@ -38,11 +39,13 @@ class PowerDNSAPIClient() { val response = client.newCall(request).execute() if(!response.isSuccessful) { - throw gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java) + val error = gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java) + throw error } return response } + @Throws(PowerDNSAPIError::class) fun deleteZone(zoneName: String): Response { val request = Request.Builder() .url("$apiUrl/api/v1/servers/localhost/zones/$zoneName") @@ -54,11 +57,13 @@ class PowerDNSAPIClient() { val response = client.newCall(request).execute() if(!response.isSuccessful) { - throw gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java) + val error = gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java) + throw error } return response } + @Throws(PowerDNSAPIError::class) fun createRecord(zoneName: String, recordName: String, recordType: String, recordContent: String): Response { val body = gson.toJson(mapOf( "name" to recordName, @@ -75,11 +80,13 @@ class PowerDNSAPIClient() { val response = client.newCall(request).execute() if(!response.isSuccessful) { - throw gson.fromJson(response.body?.string(), Error::class.java) + val error = gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java) + throw error } return response } + @Throws(PowerDNSAPIError::class) fun updateRecord(zoneName: String, recordName: String, recordType: String, recordContent: String): Response { val body = gson.toJson(mapOf( "content" to recordContent @@ -94,11 +101,13 @@ class PowerDNSAPIClient() { val response = client.newCall(request).execute() if(!response.isSuccessful) { - throw gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java) + val error = gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java) + throw error } return response } + @Throws(PowerDNSAPIError::class) fun deleteRecord(zoneName: String, recordName: String, recordType: String): Response { val request = Request.Builder() .url("$apiUrl/api/v1/servers/localhost/zones/$zoneName/records/$recordName/$recordType") @@ -110,10 +119,11 @@ class PowerDNSAPIClient() { val response = client.newCall(request).execute() if(!response.isSuccessful) { - throw gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java) + val error = gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java) + throw error } return response } } -data class PowerDNSAPIError(val error: String, val errors: List): RuntimeException(error) \ No newline at end of file +class PowerDNSAPIError(val error: String, val errors: List): RuntimeException(error) \ No newline at end of file