Skip to content

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

Closed

Description

@BartoszMiller

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);
  }

Activity

  1. gromspys commented on Oct 24, 2024

    @gromspys
    Contributor

    Yes. It looks like a bug.

  2. aryanttripathi commented on Nov 3, 2024

    @aryanttripathi

    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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions