Skip to content

Commit

Permalink
add webclient handling for 404 response
Browse files Browse the repository at this point in the history
  • Loading branch information
mhuta committed Dec 7, 2022
1 parent 2ba2f73 commit 3eb380f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import org.springframework.util.StringUtils
import org.springframework.web.context.request.RequestContextHolder
import org.springframework.web.context.request.ServletRequestAttributes
import org.springframework.web.reactive.function.client.*
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import java.util.*
import java.util.function.Consumer


@Component
class UserAppClient(
val webClient: WebClient,
Expand All @@ -49,9 +49,13 @@ class UserAppClient(
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToFlux(UserAppSubscriptionOrder::class.java)
.onErrorResume(WebClientResponseException::class.java, this::handleNotFoundResponse)
.blockFirst()
}

private fun handleNotFoundResponse(exception: WebClientResponseException) =
if (exception.rawStatusCode == 404) Flux.empty<UserAppSubscriptionOrder>() else Mono.error<UserAppSubscriptionOrder>(exception)

fun checkSubscription(): UserAppSubscriptionStatus? {
logger.debug { "Checking user subscription in user app" }
return webClient.get()
Expand All @@ -68,6 +72,7 @@ class UserAppClient(
class UserAppClientConfiguration {
@Value("\${spring.security.oauth2.client.registration.user-app-client.username:''}")
lateinit var username: String;

@Value("\${spring.security.oauth2.client.registration.user-app-client.password:''}")
lateinit var password: String;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ enum class NotificationType {


data class UserAppSubscriptionOrder (
val orderId: String?,
val transactionId: String?,
val status: String?
val orderId: String,
val transactionId: String,
val status: String
)

data class UserAppSubscriptionStatus(
Expand Down

0 comments on commit 3eb380f

Please sign in to comment.