-
Notifications
You must be signed in to change notification settings - Fork 38.4k
URL and HTTP method in rest client exception message #26480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -175,11 +207,29 @@ private String getErrorMessage( | |||
* @see HttpServerErrorException#create | |||
*/ | |||
protected void handleError(ClientHttpResponse response, HttpStatus statusCode) throws IOException { | |||
handleError(null, null, response, statusCode); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
throw new UnknownHttpStatusCodeException(message, | ||
response.getRawStatusCode(), response.getStatusText(), | ||
response.getHeaders(), body, getCharset(response)); | ||
} | ||
handleError(response, statusCode); | ||
handleError(url, method, response, statusCode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the protected method that's now bypassed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!