mirror of
https://github.com/dalbodeule/sh0rt.kr-pdns.git
synced 2025-08-10 21:41:13 +00:00
fix pdns api clients (retry 17x)
This commit is contained in:
18
src/main/kotlin/space/mori/dnsapi/GsonConfig.kt
Normal file
18
src/main/kotlin/space/mori/dnsapi/GsonConfig.kt
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package space.mori.dnsapi
|
||||||
|
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.GsonBuilder
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
class GsonConfig {
|
||||||
|
@Bean
|
||||||
|
fun gson(): Gson {
|
||||||
|
return GsonBuilder()
|
||||||
|
.setDateFormat("yyyy-MM-dd HH:mm:ss")
|
||||||
|
.registerTypeAdapter(PowerDNSAPIError::class.java, PowerDNSAPIErrorDeserializer())
|
||||||
|
.create()
|
||||||
|
}
|
||||||
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
package space.mori.dnsapi
|
package space.mori.dnsapi
|
||||||
|
|
||||||
import com.google.gson.Gson
|
import com.google.gson.*
|
||||||
import com.google.gson.annotations.SerializedName
|
import com.google.gson.annotations.SerializedName
|
||||||
import okhttp3.MediaType.Companion.toMediaType
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
@@ -9,6 +9,8 @@ import okhttp3.RequestBody.Companion.toRequestBody
|
|||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import org.springframework.beans.factory.annotation.Value
|
import org.springframework.beans.factory.annotation.Value
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
import java.lang.reflect.Type
|
||||||
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class PowerDNSAPIClient() {
|
class PowerDNSAPIClient() {
|
||||||
@@ -132,6 +134,21 @@ data class PowerDNSAPIError(
|
|||||||
@SerializedName("error") val error: String,
|
@SerializedName("error") val error: String,
|
||||||
@SerializedName("errors") val errors: List<String>
|
@SerializedName("errors") val errors: List<String>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class PowerDNSAPIErrorDeserializer : JsonDeserializer<PowerDNSAPIError?> {
|
||||||
|
@Throws(JsonParseException::class)
|
||||||
|
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext?): PowerDNSAPIError {
|
||||||
|
val jsonObject = json.asJsonObject
|
||||||
|
val error = jsonObject["error"].asString
|
||||||
|
val errorsJson = jsonObject["errors"].asJsonArray
|
||||||
|
val errors: MutableList<String> = ArrayList()
|
||||||
|
for (element in errorsJson) {
|
||||||
|
errors.add(element.asString)
|
||||||
|
}
|
||||||
|
return PowerDNSAPIError(error, errors)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class PowerDNSAPIException(private val error: PowerDNSAPIError): RuntimeException(error.error) {
|
class PowerDNSAPIException(private val error: PowerDNSAPIError): RuntimeException(error.error) {
|
||||||
val errors: List<String>
|
val errors: List<String>
|
||||||
get() = error.errors
|
get() = error.errors
|
||||||
|
Reference in New Issue
Block a user