mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-27 10:28:28 +00:00
Better message text for ResponseException
This avoids messages with malformed URLs, like "org.elasticsearch.client.ResponseException: PUT http://127.0.0.1:9502customer: HTTP/1.1 400 Bad Request". Relates #26564
This commit is contained in:
parent
120ddd99c3
commit
e9deb62546
@ -24,6 +24,7 @@ import org.apache.http.entity.BufferedHttpEntity;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Exception thrown when an elasticsearch node responds to a request with a status code that indicates an error.
|
||||
@ -39,8 +40,13 @@ public final class ResponseException extends IOException {
|
||||
}
|
||||
|
||||
private static String buildMessage(Response response) throws IOException {
|
||||
String message = response.getRequestLine().getMethod() + " " + response.getHost() + response.getRequestLine().getUri()
|
||||
+ ": " + response.getStatusLine().toString();
|
||||
String message = String.format(Locale.ROOT,
|
||||
"method [%s], host [%s], URI [%s], status line [%s]",
|
||||
response.getRequestLine().getMethod(),
|
||||
response.getHost(),
|
||||
response.getRequestLine().getUri(),
|
||||
response.getStatusLine().toString()
|
||||
);
|
||||
|
||||
HttpEntity entity = response.getEntity();
|
||||
if (entity != null) {
|
||||
|
@ -36,6 +36,7 @@ import org.apache.http.util.EntityUtils;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
@ -74,8 +75,14 @@ public class ResponseExceptionTests extends RestClientTestCase {
|
||||
assertNull(responseException.getResponse().getEntity());
|
||||
}
|
||||
|
||||
String message = response.getRequestLine().getMethod() + " " + response.getHost() + response.getRequestLine().getUri()
|
||||
+ ": " + response.getStatusLine().toString();
|
||||
String message = String.format(Locale.ROOT,
|
||||
"method [%s], host [%s], URI [%s], status line [%s]",
|
||||
response.getRequestLine().getMethod(),
|
||||
response.getHost(),
|
||||
response.getRequestLine().getUri(),
|
||||
response.getStatusLine().toString()
|
||||
);
|
||||
|
||||
if (hasBody) {
|
||||
message += "\n" + responseBody;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user