Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PI-2397 Add retries for detail URL client #4781

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import org.springframework.beans.factory.annotation.Value
import org.springframework.core.ParameterizedTypeReference
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Service
import org.springframework.web.client.HttpStatusCodeException
import org.springframework.web.client.RestClient
import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent
import uk.gov.justice.digital.hmpps.retry.retry
import java.net.URI

@Service
Expand All @@ -28,11 +30,15 @@ class DomainEventDetailService(
getDetail(validate(detailUrl), object : ParameterizedTypeReference<T>() {})

fun <T> getDetail(uri: URI, type: ParameterizedTypeReference<T>): T =
requireNotNull(restClient).get().uri(uri).retrieve().body<T>(type)!!
retry(3, listOf(HttpStatusCodeException::class)) {
requireNotNull(restClient).get().uri(uri).retrieve().body<T>(type)!!
}

final inline fun <reified T> getDetailResponse(event: HmppsDomainEvent): ResponseEntity<T> =
getDetailResponse(validate(event.detailUrl), object : ParameterizedTypeReference<T>() {})

fun <T> getDetailResponse(uri: URI, type: ParameterizedTypeReference<T>): ResponseEntity<T> =
requireNotNull(restClient).get().uri(uri).retrieve().toEntity<T>(type)
retry(3, listOf(HttpStatusCodeException::class)) {
requireNotNull(restClient).get().uri(uri).retrieve().toEntity<T>(type)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import org.springframework.http.HttpRequest
import org.springframework.http.client.ClientHttpRequestExecution
import org.springframework.http.client.ClientHttpRequestInterceptor
import org.springframework.http.client.ClientHttpResponse
import org.springframework.web.client.RestClientException
import uk.gov.justice.digital.hmpps.retry.retry
import java.io.IOException
import java.time.Duration
Expand All @@ -15,7 +14,7 @@ class RetryInterceptor(private val retries: Int = 3, private val delay: Duration
request: HttpRequest,
body: ByteArray,
execution: ClientHttpRequestExecution
): ClientHttpResponse = retry(retries, listOf(RestClientException::class, IOException::class), delay) {
): ClientHttpResponse = retry(retries, listOf(IOException::class), delay) {
execution.execute(request, body)
}
}
Loading