From 496a7d2fd68982fb09fcdbf879dc3a7cc45b6114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Tue, 10 Jun 2025 11:20:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=94=99=E8=AF=AF=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 20 ++++++++++++++++++-- app/utils/CheckUtils.php | 6 +----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/common.php b/app/common.php index 10d3960..06befa5 100644 --- a/app/common.php +++ b/app/common.php @@ -357,7 +357,7 @@ function check_proxy($url, $proxy_server, $proxy_port, $type, $proxy_user, $prox throw new Exception('HTTP状态码异常:' . $httpCode); } } catch (GuzzleException $e) { - throw new Exception($e->getMessage()); + throw new Exception(guzzle_error($e)); } } @@ -519,10 +519,26 @@ function http_request($url, $data = null, $referer = null, $cookie = null, $head 'body' => $response->getBody()->getContents() ]; } catch (GuzzleException $e) { - throw new Exception('请求失败: ' . $e->getMessage()); + throw new Exception('请求失败: ' . guzzle_error($e)); } } +function guzzle_error($e) +{ + $errmsg = $e->getMessage(); + if (preg_match('/^cURL error \d+: /', $errmsg)) { + $errmsg = preg_replace('/^cURL error \d+: /', '', $errmsg); + } + $pos = strpos($errmsg, ' (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)'); + if ($pos !== false) { + $errmsg = substr($errmsg, 0, $pos); + } + if (strlen($errmsg) > 100) { + $errmsg = substr($errmsg, 0, 97) . '...'; + } + return $errmsg; +} + function curl_set_proxy(&$ch) { $proxy_server = config_get('proxy_server'); diff --git a/app/utils/CheckUtils.php b/app/utils/CheckUtils.php index 7ef2806..3725c96 100644 --- a/app/utils/CheckUtils.php +++ b/app/utils/CheckUtils.php @@ -82,11 +82,7 @@ class CheckUtils } } catch (GuzzleException $e) { $status = false; - $errmsg = $e->getMessage(); - if (preg_match('/^cURL error \d+: /', $errmsg)) { - $errmsg = preg_replace('/^cURL error \d+: /', '', $errmsg); - } - $errmsg = str_replace(' (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)', '', $errmsg); + $errmsg = guzzle_error($e); if (strlen($errmsg) > 100) { $errmsg = substr($errmsg, 0, 97) . '...'; }