When I request a rest api that returns “202 accepted” I’m getting an error with Webflux. Requests that result in “200 ok” working fine.
Bellow the code:
fun requestPasswordReset(email: String) = Mono.just(
Envelope(
from = Email(from),
to = listOf(Email(email)),
subject = "Hello World",
html = "<H1>Hello World!</H1>"
)
).flatMap(mailerSendClient::send)
.doOnError {
println(it.message)//202 accepted as WebClientResponseException here
}
Here is my interface:
@HttpExchange("/v1/email")
fun interface MailerSendClient {
@PostExchange
fun send(@RequestBody envelope: Envelope): Mono<Unit>
}
And my webclient config:
@Bean
fun createMailerSendClient(
@Value("${mailer-send.api.uri}") baseUrl: String,
@Value("${mailer-send.api.token}") token: String
): MailerSendClient {
val client = WebClient.builder()
.baseUrl(baseUrl)
.defaultHeader(HttpHeaders.AUTHORIZATION, "Bearer $token")
.build()
return httpServiceProxyFactory(client, MailerSendClient::class.java)
}
fun <T> httpServiceProxyFactory(webClient: WebClient, clazz: Class<T>) =
HttpServiceProxyFactory.builderFor(WebClientAdapter.create(webClient)).build()
.createClient(clazz)
It works ok, I’m able to send the email but I’m getting this strange behaviour. What am I missing?