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) . '...'; }