Merge pull request #9790 from dataease/pr@dev-v2@perf_http_utils

perf: http工具类校验url
This commit is contained in:
fit2cloud-chenyw 2024-05-23 10:41:25 +08:00 committed by GitHub
commit 2bbc3d9c45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -93,8 +93,14 @@ public class HttpClientUtil {
httpGet.addHeader(key, header.get(key)); httpGet.addHeader(key, header.get(key));
} }
HttpResponse response = httpClient.execute(httpGet); HttpResponse response = httpClient.execute(httpGet);
int statusCode = response.getStatusLine().getStatusCode(); if (response.getStatusLine().getStatusCode() >= 400) {
return statusCode <= 400; String msg = EntityUtils.toString(response.getEntity(), config.getCharset());
if (StringUtils.isEmpty(msg)) {
msg = "StatusCode: " + response.getStatusLine().getStatusCode();
}
throw new Exception(msg);
}
return true;
} catch (Exception e) { } catch (Exception e) {
logger.error("HttpClient查询失败", e); logger.error("HttpClient查询失败", e);
throw new DEException(SYSTEM_INNER_ERROR.code(), "HttpClient查询失败: " + e.getMessage()); throw new DEException(SYSTEM_INNER_ERROR.code(), "HttpClient查询失败: " + e.getMessage());