I have to call a third-party endpoint in my service and need to fetch the errors directly from the endpoint while an error has occurred. I am using WebClient to call the endpoint and below is the snippet.
webClient.post()
.uri(uri)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.bodyValue(request)
.retrieve()
.onStatus(BAD_REQUEST::equals, clientResponse -> clientResponse
.bodyToMono(ApiException.class)
.map(ApiException::getErrors)
.map(e -> e.get(0).getDetail())
.map(TestException::new));
Getting below error while mapping the exception response: [Request processing failed; nested exception is org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'application/json' not supported for bodyType=com.squareup.square.exceptions.ApiException] with root cause.
Any help would be appreciated.Thanks!