From df32c786f98c57b45a84de7f373da0edb3961dfa Mon Sep 17 00:00:00 2001 From: KFCFans Date: Sat, 14 Nov 2020 11:37:23 +0800 Subject: [PATCH] fix: HttpUtils --- .../com/github/kfcfans/powerjob/common/utils/HttpUtils.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/powerjob-common/src/main/java/com/github/kfcfans/powerjob/common/utils/HttpUtils.java b/powerjob-common/src/main/java/com/github/kfcfans/powerjob/common/utils/HttpUtils.java index df39522a..b4c4beeb 100644 --- a/powerjob-common/src/main/java/com/github/kfcfans/powerjob/common/utils/HttpUtils.java +++ b/powerjob-common/src/main/java/com/github/kfcfans/powerjob/common/utils/HttpUtils.java @@ -1,5 +1,6 @@ package com.github.kfcfans.powerjob.common.utils; +import com.github.kfcfans.powerjob.common.PowerJobException; import okhttp3.*; import java.io.IOException; @@ -41,7 +42,8 @@ public class HttpUtils { private static String execute(Request request) throws IOException { try (Response response = client.newCall(request).execute()) { - if (response.code() == HTTP_SUCCESS_CODE) { + int responseCode = response.code(); + if (responseCode == HTTP_SUCCESS_CODE) { ResponseBody body = response.body(); if (body == null) { return null; @@ -49,8 +51,8 @@ public class HttpUtils { return body.string(); } } + throw new PowerJobException(String.format("http request failed,code=%d", responseCode)); } - return null; } }