Skip to content

Commit

Permalink
Exclude URL query from WebClientResponseException
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrosser committed Jan 9, 2024
1 parent f9cb0df commit 811832b
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.web.reactive.function.client;

import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
Expand All @@ -30,6 +32,7 @@
import org.springframework.http.HttpStatusCode;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

/**
* Exceptions that contain actual HTTP response data.
Expand Down Expand Up @@ -99,7 +102,19 @@ public WebClientResponseException(

private static String initMessage(HttpStatusCode status, String reasonPhrase, @Nullable HttpRequest request) {
return status.value() + " " + reasonPhrase +
(request != null ? " from " + request.getMethod() + " " + request.getURI() : "");
(request != null ? " from " + request.getMethod() + " " + getUriToLog(request.getURI()) : "");
}

private static URI getUriToLog(URI uri) {
if (StringUtils.hasText(uri.getQuery())) {
try {
uri = new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), null, null);
}
catch (URISyntaxException ex) {
// ignore
}
}
return uri;
}

/**
Expand Down

0 comments on commit 811832b

Please sign in to comment.