client-java: handle server HTTP errors (#3762)

* client-java: handle server HTTP errors

* Update SeaweedWrite.java
This commit is contained in:
kvtb 2022-09-29 19:20:14 +00:00 committed by GitHub
parent e00a12b099
commit 5e9039d728
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -149,6 +149,13 @@ public class SeaweedWrite {
CloseableHttpResponse response = SeaweedUtil.getClosableHttpClient().execute(post);
try {
if (response.getStatusLine().getStatusCode() / 100 != 2) {
if (response.getEntity().getContentType() != null && response.getEntity().getContentType().getValue().equals("application/json")) {
throw new IOException(EntityUtils.toString(response.getEntity(), "UTF-8"));
} else {
throw new IOException(response.getStatusLine().getReasonPhrase());
}
}
String etag = response.getLastHeader("ETag").getValue();