URL and HTTP method in rest client exception message - #26480
Conversation
| @@ -132,9 +154,10 @@ public void handleError(ClientHttpResponse response) throws IOException { | |||
| * </pre> | |||
| */ | |||
| private String getErrorMessage( | |||
There was a problem hiding this comment.
Ideally, I'd make this method protected - so that I can override it to extract some more specific information from responses that return HTML, XML or some other nonstandard data.
There was a problem hiding this comment.
Considering something beyond 5.3.x - what about this one?
I'd love to have an extension point where I can further customize the response body preview - format it right, remove some tags, etc.
A long time ago, here: https://github.com/spring-projects/spring-framework/pull/1956/files - I even thought about a separate class to extract the body. But a protected method would be just fine.
rstoyanchev
left a comment
There was a problem hiding this comment.
Given the change of protected methods I'd rather avoid this change at this stage of the 5.3.x branch. As far as I can see you can still make it happen in your own custom extension of DefaultResponseErrorHandler, right? It just wouldn't be out of the box.
| */ | ||
| protected void handleError(ClientHttpResponse response, HttpStatus statusCode) throws IOException { | ||
| handleError(null, null, response, statusCode); | ||
| } |
There was a problem hiding this comment.
This is a protected method that is now bypassed. Something to consider for a minor/major release but not at this stage of the 5.3.x branch.
There was a problem hiding this comment.
Thanks for looking into that!
Initially, I didn't think of squeezing it into 5.3. I'd be very happy to do so - but I think the previous changes broke something in spring-integration, so it might not be that easy.
I tried to not to change the behaviour of this method at all. I can also try to rewrite this to make it more 5.3-compatible. But If you think it makes more sense to wait - let's wait.
I'm not sure if you're refering to making |
| response.getHeaders(), body, getCharset(response)); | ||
| } | ||
| handleError(response, statusCode); | ||
| handleError(url, method, response, statusCode); |
There was a problem hiding this comment.
This is the protected method that's now bypassed.
There was a problem hiding this comment.
Thanks for the explanation!
Then it can definitely wait for a future Spring release. I'm not in a particular hurry - any custom extensions would well enough.
Should I close the PR, or just keep it here?
Also - is it something that you'd see easy to port into WebClient? Would it make sense to make these two in sync?
There was a problem hiding this comment.
I think we can close it for now. On the WebClient side it looks we do have the URL and HTTP method in WebClientResponseException.
There was a problem hiding this comment.
Thanks for the feedback @rstoyanchev !
Is there a chance to squeeze this in a future Spring Framework release? Should I come back once it's announced?
There was a problem hiding this comment.
Yes, of course. We can probably re-open this PR then.
I'm talking about the call to the protected handleError method that is now bypassed. |
Dear team,
This is a followup of a discussion in a past PR: #1956
The rest client exception contains a preview of the body, which is great, and it helps a lot to quickly diagnose errors.
Now, the stacktrace looks like this:
I'd like to add the HTTP method and URL to the error, so that the stacktrace looks like this:
Thank you!