More details (URL, method, body preview) in FeignClient(Server)Exception message
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.8k
- Forks
- 1.9k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 41
Description
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: https://github.com/spring-projects/spring-framework/pull/1956 . I can provide a pull request for this, if you like the general concept.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in FeignException.java at the errorStatus and clientErrorStatus methods shown in the issue, then inspect how the request and response details are available there. Define the message contents and a bounded response-body representation, and add coverage for the requested status, method, URL, and response details. Done means the exception message includes those details without retaining an unbounded body.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100