Skip to content

Commit

Permalink
返回503时包装为connect异常抛出,统一Http框架在不同操作系统下的行为
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Jul 26, 2023
1 parent 3f0399d commit 2f54272
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.nop.commons.concurrent.executor.IThreadPoolExecutor;
import io.nop.commons.util.StringHelper;
import io.nop.http.api.HttpApiConstants;
import io.nop.http.api.HttpStatus;
import io.nop.http.api.client.DownloadOptions;
import io.nop.http.api.client.HttpClientConfig;
import io.nop.http.api.client.HttpRequest;
Expand Down Expand Up @@ -215,6 +216,10 @@ java.net.http.HttpRequest.BodyPublisher toBody(String dataType, Object body) {
}

IHttpResponse toHttpResponse(HttpResponse<byte[]> response) {
// 某些MAC系统或者JDK版本中连接不上也不会抛出connect异常,而是会返回503错误码
if (response.statusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE)
throw new NopConnectException(ERR_HTTP_CONNECT_FAIL);

DefaultHttpResponse ret = new DefaultHttpResponse();
ret.setHttpStatus(response.statusCode());
ret.setBodyAsBytes(response.body());
Expand Down

0 comments on commit 2f54272

Please sign in to comment.