优化错误信息

This commit is contained in:
耗子 2025-06-10 11:20:02 +08:00
parent eb950663e7
commit 496a7d2fd6
No known key found for this signature in database
GPG Key ID: C964D7226D045DAA
2 changed files with 19 additions and 7 deletions

View File

@ -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');

View File

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