Skip to content

More details (URL, method, body preview) in FeignClient(Server)Exception message #1048

@jerzykrlk

Description

@jerzykrlk

Can we make the FeignException message look like:

409 Conflict during [POST] to [http://localhost:8080/endpoint], response: [{"error":{"code":409,"message":"You already own this bucket. Please select another name."}}]

instead of just:

status 409 reading FeignClient#getResponse()

Reason:
Applications using Feign, communicate with multiple external systems.

As a developer, when I try to diagnose an issue in production, from the default exception message I cannot find out about:

  • HTTP endpoint,
  • HTTP method,
  • the error response, which usually contains something interesting.

I think that the new format would improve developer experience. I would like to see the complete information from the moment when the issue occurred: which external system returned an error, what endpoint and response body was. Just like that.

This would automatically appear in the logs, so I do not need to 1st - search through the stacktraces to see which request that was, 2nd - try to reproduce the issue to see the actual response body. Especially hard with non-deterministic errors.

There are other ways to do it, but I think the exception message is most natural. Other ways I know, involve extra error handling code all around the application. And the new format would be almost no changes to users' existing code base.

Actual (sample of current Feign logs):

feign.FeignException$Conflict: status 409 reading FeignClient#getResponse()

	at feign.FeignException.clientErrorStatus(FeignException.java:118)
	at feign.FeignException.errorStatus(FeignException.java:91)
	at feign.FeignException.errorStatus(FeignException.java:86)

Expected (what the log entry could look like):

409 Conflict during [POST] to [http://localhost:8080/endpoint], response: [{"error":{"code":409,"message":"You already own this bucket. Please select another name."}}]

feign.FeignException$Conflict: 409 Conflict during [POST] to [http://localhost:8080/endpoint], response: [{"error":{"code":409,"message":"You already own this bucket. Please select another name."}}]

	at feign.FeignException.clientErrorStatus(FeignException.java:118)
	at feign.FeignException.errorStatus(FeignException.java:91)
	at feign.FeignException.errorStatus(FeignException.java:86)

I have implemented this multiple times already, in multiple projects. I think Feign would be a better place to do that.

Note - back in Feign 10.0.1, the message contained the complete body of the response (any size, even 1MB worked), which might cause problems. But I think the response can be abbreviated to just first 100 - 500 characters of the body.

This is basically the same idea as here: spring-projects/spring-framework#1956 . I can provide a pull request for this, if you like the general concept.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feign-12Issues that are related to the next major releaseproposalProposed Specification or API change

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions