OpenFeign / feign

Feign makes writing java http clients easier
Apache License 2.0
9.51k stars 1.93k forks source link

FeignException::responseBody() returns request body instead of response body #2618

Open BartoszMiller opened 1 month ago

BartoszMiller commented 1 month ago

I wanted to retrieve response body from a FeignException, but FeignException::responseBody() returns request body of my request. Is it intentional or is it a bug? One of the FeignException constructors, as the parameter name implies, expects response body. However, in the errorReading method request.body() is passed instead.

static FeignException errorReading(Request request, Response response, IOException cause) {
    return new FeignException(
        response.status(),
        format("%s reading %s %s", cause.getMessage(), request.httpMethod(), request.url()),
        request,
        cause,
        request.body(),
        request.headers());
  }
protected FeignException(
      int status,
      String message,
      Request request,
      Throwable cause,
      byte[] responseBody,
      Map<String, Collection<String>> responseHeaders) {
    super(message, cause);
    this.status = status;
    this.responseBody = responseBody;
    this.responseHeaders = caseInsensitiveCopyOf(responseHeaders);
    this.request = checkRequestNotNull(request);
  }
gromspys commented 1 month ago

Yes. It looks like a bug.

Aryant-Tripathi commented 3 weeks ago

Hey @gromspys, I want to work around feign and learn about it. Do we need to change the constructor params since it expects the response body as byte[] and response? getBody() is a String in nature.

What do you think we can do here?