fix pdns api clients (retry 22x)

add Throwable handler
This commit is contained in:
dalbodeule 2024-06-07 20:49:41 +09:00
parent 7b408eb946
commit 25a7b6ca85
No known key found for this signature in database
GPG Key ID: EFA860D069C9FA65

View File

@ -12,7 +12,7 @@ class GlobalExceptionHandler {
@ExceptionHandler(PowerDNSAPIException::class) @ExceptionHandler(PowerDNSAPIException::class)
fun handlePowerDNSAPIException(ex: PowerDNSAPIException): ResponseEntity<ApiResponseDTO<Nothing>> { fun handlePowerDNSAPIException(ex: PowerDNSAPIException): ResponseEntity<ApiResponseDTO<Nothing>> {
var idx = 0 var idx = 0
val errors = mutableListOf(ErrorOrMessage(idx, ex.message ?: "")) val errors = mutableListOf(ErrorOrMessage(idx, ex.message ?: "PowerDNSAPIException"))
ex.errors?.forEach{ ex.errors?.forEach{
errors.add(ErrorOrMessage(idx++, it)) errors.add(ErrorOrMessage(idx++, it))
} }
@ -25,4 +25,17 @@ class GlobalExceptionHandler {
return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body(response) return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body(response)
} }
@ExceptionHandler(Throwable::class)
fun handleException(ex: Throwable): ResponseEntity<ApiResponseDTO<Nothing>> {
val errors = mutableListOf(ErrorOrMessage(0, ex.message ?: "Error"))
val response = ApiResponseDTO(
success = false,
errors = errors,
result = null
)
return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body(response)
}
} }