request 개별 적용

webClient.get()
    .uri { uriBuilder ->
        uriBuilder.path("/v1/~~~~~")
            .queryParam("aaa", 11)
            .queryParam("bbb", 222)
            .build()
    }
    .retrieve()
	.onStatus(HttpStatus::is5xxServerError) {
        val response = it.bodyToMono<Coupon.ErrorResponse>().block()
        Mono.error(HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, response.detailMessage ?: ""))
    }
    .awaitBody<List<ResponseItem>>()

 

webclient 적용

ExchangeFilterFunction.ofResponseProcessor { clientResponse: ClientResponse ->
    if (clientResponse.statusCode().is5xxServerError) {
        return@ofResponseProcessor clientResponse.bodyToMono(String::class.java)
            .flatMap { errorBody: String? ->
                val body = objectMapper.readValue(errorBody, ErrorResponse::class.java)
                Mono.error(
                    HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, body.detailMessage ?: "")
                )
            }
    } else {
        return@ofResponseProcessor Mono.just(clientResponse)
    }
}

 

'Develop' 카테고리의 다른 글

몽고에 저장되는 json에 쓸수 있는 정규 표현식  (0) 2023.08.10
Protobuf reserved  (0) 2022.06.25
젠킨스 파이프라인에서 다른 job 실행  (0) 2022.04.01
mysql rows to columns  (0) 2021.10.21
DocumentDB failover 장애 시간  (0) 2021.09.28

+ Recent posts