mirror of
https://github.com/dalbodeule/sh0rt.kr-pdns.git
synced 2025-08-09 21:21:12 +00:00
fix pdns api clients (retry 11x)
This commit is contained in:
@@ -6,7 +6,9 @@ import io.swagger.v3.oas.annotations.media.Schema
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
import space.mori.dnsapi.PowerDNSAPIError
|
||||
import space.mori.dnsapi.db.Domain
|
||||
import space.mori.dnsapi.dto.*
|
||||
@@ -32,7 +34,10 @@ class DomainController(
|
||||
} catch(e : PowerDNSAPIError) {
|
||||
val errors = mutableListOf(e.error)
|
||||
errors.addAll(e.errors)
|
||||
return ApiResponseDTO(false, errors = errors.map { ErrorOrMessage(1, it) })
|
||||
throw ResponseStatusException(
|
||||
HttpStatus.EXPECTATION_FAILED,
|
||||
ApiResponseDTO(false, errors = errors.map { ErrorOrMessage(1, it) }, result = listOf(null)).toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +56,9 @@ class DomainController(
|
||||
} catch(e : PowerDNSAPIError) {
|
||||
val errors = mutableListOf(e.error)
|
||||
errors.addAll(e.errors)
|
||||
return ApiResponseDTO(false, errors = errors.map { ErrorOrMessage(1, it) })
|
||||
throw ResponseStatusException(HttpStatus.EXPECTATION_FAILED,
|
||||
ApiResponseDTO(false, errors = errors.map { ErrorOrMessage(1, it) }, result = listOf(null)).toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +75,9 @@ class DomainController(
|
||||
} catch(e : PowerDNSAPIError) {
|
||||
val errors = mutableListOf(e.error)
|
||||
errors.addAll(e.errors)
|
||||
return ApiResponseDTO(false, errors = errors.map { ErrorOrMessage(1, it) })
|
||||
throw ResponseStatusException(HttpStatus.EXPECTATION_FAILED,
|
||||
ApiResponseDTO(false, errors = errors.map { ErrorOrMessage(1, it) }, result = listOf(null)).toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +96,9 @@ class DomainController(
|
||||
} catch(e : PowerDNSAPIError) {
|
||||
val errors = mutableListOf(e.error)
|
||||
errors.addAll(e.errors)
|
||||
return ApiResponseDTO(false, errors = errors.map { ErrorOrMessage(1, it) })
|
||||
throw ResponseStatusException(HttpStatus.EXPECTATION_FAILED,
|
||||
ApiResponseDTO(false, errors = errors.map { ErrorOrMessage(1, it) }, result = listOf(null)).toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -6,7 +6,9 @@ import io.swagger.v3.oas.annotations.media.Schema
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
import space.mori.dnsapi.PowerDNSAPIError
|
||||
import space.mori.dnsapi.dto.*
|
||||
import space.mori.dnsapi.service.RecordService
|
||||
@@ -30,7 +32,9 @@ class RecordController(
|
||||
} catch(e : PowerDNSAPIError) {
|
||||
val errors = mutableListOf(e.error)
|
||||
errors.addAll(e.errors)
|
||||
return ApiResponseDTO(false, errors = errors.map { ErrorOrMessage(1, it) })
|
||||
throw ResponseStatusException(HttpStatus.EXPECTATION_FAILED,
|
||||
ApiResponseDTO(false, errors = errors.map { ErrorOrMessage(1, it) }, result = listOf(null)).toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +51,9 @@ class RecordController(
|
||||
} catch(e : PowerDNSAPIError) {
|
||||
val errors = mutableListOf(e.error)
|
||||
errors.addAll(e.errors)
|
||||
return ApiResponseDTO(false, errors = errors.map { ErrorOrMessage(1, it) })
|
||||
throw ResponseStatusException(HttpStatus.EXPECTATION_FAILED,
|
||||
ApiResponseDTO(false, errors = errors.map { ErrorOrMessage(1, it) }, result = listOf(null)).toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +70,9 @@ class RecordController(
|
||||
} catch(e : PowerDNSAPIError) {
|
||||
val errors = mutableListOf(e.error)
|
||||
errors.addAll(e.errors)
|
||||
return ApiResponseDTO(false, errors = errors.map { ErrorOrMessage(1, it) })
|
||||
throw ResponseStatusException(HttpStatus.EXPECTATION_FAILED,
|
||||
ApiResponseDTO(false, errors = errors.map { ErrorOrMessage(1, it) }, result = listOf(null)).toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +90,9 @@ class RecordController(
|
||||
} catch(e : PowerDNSAPIError) {
|
||||
val errors = mutableListOf(e.error)
|
||||
errors.addAll(e.errors)
|
||||
return ApiResponseDTO(false, errors = errors.map { ErrorOrMessage(1, it) })
|
||||
throw ResponseStatusException(HttpStatus.EXPECTATION_FAILED,
|
||||
ApiResponseDTO(false, errors = errors.map { ErrorOrMessage(1, it) }, result = listOf(null)).toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +109,9 @@ class RecordController(
|
||||
} catch(e : PowerDNSAPIError) {
|
||||
val errors = mutableListOf(e.error)
|
||||
errors.addAll(e.errors)
|
||||
return ApiResponseDTO(false, errors = errors.map { ErrorOrMessage(1, it) })
|
||||
throw ResponseStatusException(HttpStatus.EXPECTATION_FAILED,
|
||||
ApiResponseDTO(false, errors = errors.map { ErrorOrMessage(1, it) }, result = listOf(null)).toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +1,17 @@
|
||||
package space.mori.dnsapi.dto
|
||||
|
||||
import com.google.gson.GsonBuilder
|
||||
|
||||
val gson = GsonBuilder().setPrettyPrinting().create()
|
||||
|
||||
data class ApiResponseDTO<T>(
|
||||
val success: Boolean = true,
|
||||
val errors: List<ErrorOrMessage> = listOf(),
|
||||
val messages: List<ErrorOrMessage> = listOf(),
|
||||
val result: T? = null
|
||||
)
|
||||
) {
|
||||
override fun toString(): String = gson.toJson(this)
|
||||
}
|
||||
|
||||
data class ErrorOrMessage(
|
||||
val code: Int,
|
||||
|
Reference in New Issue
Block a user