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

HTTP Interface Clients should return ResponseEntity even if a 40X or 50X error occurs #33581

Closed
amoffet opened this issue Sep 23, 2024 · 1 comment
Assignees
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@amoffet
Copy link

amoffet commented Sep 23, 2024

Affects: Spring Web 6.1.X

Given a simple method in FooInterface such as

  @GetExchange("/foo")
  Mono<ResponseEntity<Foo>> getFoo();

with a 'standard' WebClient backing it.

The factory is also 'generic':

    HttpServiceProxyFactory factory = HttpServiceProxyFactory
      .builderFor(WebClientAdapter.create(webClient))
      .build();

    return factory.createClient(FooInterface.class);

When the client is used and a 40X or 50X response occurs, then the WebClient throws a WebClientResponseException - which is unexpected - as I would think that having specified Mono<ResponseEntity<Foo>> as the return type would have returned a ResponseEntity with status 40X or 50X (acknowledging the reactive component of this).

Looking at the factory code, it is aware of the return type, and therefore I would expect a response that is consistent with the declared return type - in other words, a Mono<ResponseEntity<Foo>>.

I have not found a way to work around this - meaning obtaining a behavior consistent with the return type - in the same manner that exchange() would work. This is another odd part of this, as exchange() is deprecated and we now work with exchangeToMono() - which is distinctly a client feature that seems too low level to be a part of HTTP interface clients. So maybe - works as designed?

Instead, I've had to use the normal handling of errors to 'coerce' the behavior I want for a given method. With this, I can do what I want, but it seems this may be a bug - or something that can be clarified in the documentation.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 23, 2024
@simonbasle simonbasle added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 25, 2024
@simonbasle simonbasle self-assigned this Sep 25, 2024
@simonbasle
Copy link
Contributor

@amoffet the official way around this is to customize the underlying WebClient, as described in the HTTP interface client documentation's error handling section

@simonbasle simonbasle closed this as not planned Won't fix, can't repro, duplicate, stale Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

3 participants