@@ -293,10 +293,18 @@ private static void handleBinaryResponse(Response okResponse, HttpResponse respo
293293 return ;
294294 }
295295 if (is != null ) {
296- FileAndSize fs = saveInputStreamToTempFile (is , "easyPostman_download_" , null , contentLengthHeader );
297- response .filePath = fs .file .getAbsolutePath ();
298- response .body = I18nUtil .getMessage (MessageKeys .BINARY_SAVED_TEMP_FILE );
299- response .bodySize = fs .size ;
296+ try {
297+ FileAndSize fs = saveInputStreamToTempFile (is , "easyPostman_download_" , null , contentLengthHeader );
298+ response .filePath = fs .file .getAbsolutePath ();
299+ response .body = I18nUtil .getMessage (MessageKeys .BINARY_SAVED_TEMP_FILE );
300+ response .bodySize = fs .size ;
301+ } catch (EOFException e ) {
302+ // 处理下载过程中连接中断的情况
303+ log .error ("Failed to download complete binary response: {}" , e .getMessage ());
304+ response .body = I18nUtil .getMessage (MessageKeys .RESPONSE_INCOMPLETE , e .getMessage ());
305+ response .bodySize = 0 ;
306+ response .filePath = null ;
307+ }
300308 } else {
301309 response .body = I18nUtil .getMessage (MessageKeys .NO_RESPONSE_BODY );
302310 response .bodySize = 0 ;
@@ -335,7 +343,21 @@ private static void handleTextResponse(Response okResponse, HttpResponse respons
335343 return ;
336344 }
337345 if (body != null ) {
338- byte [] bytes = body .bytes ();
346+ byte [] bytes ;
347+ try {
348+ bytes = body .bytes ();
349+ } catch (EOFException e ) {
350+ // 处理响应体不完整的情况(网络中断、服务器过早关闭连接等)
351+ log .error ("Failed to read complete response body: {}" , e .getMessage ());
352+ response .body = I18nUtil .getMessage (MessageKeys .RESPONSE_INCOMPLETE , e .getMessage ());
353+ response .bodySize = 0 ;
354+ response .filePath = null ;
355+ return ;
356+ } catch (IOException e ) {
357+ // 处理其他 IO 异常
358+ log .error ("Error reading response body: {}" , e .getMessage (), e );
359+ throw e ;
360+ }
339361 response .bodySize = bytes .length ;
340362 if (bytes .length > getMaxBodySize ()) { // 如果解压后内容超过设置值,保存为临时文件
341363 String extension = ext != null ? ext : ".txt" ;
0 commit comments