فهرست منبع

fix: 异常直接抛出给外层

runphp 1 ماه پیش
والد
کامیت
05af6615f7
1فایلهای تغییر یافته به همراه9 افزوده شده و 13 حذف شده
  1. 9 13
      src/Hook/AppStatusHook.php

+ 9 - 13
src/Hook/AppStatusHook.php

@@ -7,11 +7,8 @@ namespace SixShop\Auth\Hook;
 use Composer\Factory;
 use SixShop\Auth\Config;
 use SixShop\Core\Attribute\Hook;
-use Symfony\Component\HttpClient\Exception\ClientException;
 use Symfony\Component\HttpClient\HttpClient;
-use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
 use Symfony\Contracts\HttpClient\HttpClientInterface;
-use think\facade\Log;
 
 class AppStatusHook
 {
@@ -20,6 +17,7 @@ class AppStatusHook
     private const string PACKAGIST_DOMAIN = 'packagist.jd29.com';
 
     private HttpClientInterface $httpClient;
+
     public function __construct(
         private readonly Config $config,
     ) {
@@ -27,16 +25,19 @@ class AppStatusHook
             $authConfigSource = Factory::createConfig()->getAuthConfigSource();
             $authFile = $authConfigSource->getName();
             if (!file_exists($authFile)) {
-                $authFile = root_path('runtime').'auth.json';
+                $authFile = root_path('runtime') . 'auth.json';
             }
         } catch (\RuntimeException) {
-            $authFile = root_path('runtime').'auth.json';
+            $authFile = root_path('runtime') . 'auth.json';
         }
         $authJsonArr = json_decode(file_get_contents($authFile), true);
         $bearerToken = $authJsonArr['bearer'][self::PACKAGIST_DOMAIN];
         $defaultOptions = [
             'base_uri' => self::BASE_URL,
             'auth_bearer' => $bearerToken,
+            'timeout' => 5,
+            'max_connect_duration' => 5,
+            'max_duration' => 15,
         ];
         $defaultOptions['verify_peer'] = $this->config->verify_peer;
         $defaultOptions['verify_host'] = $this->config->verify_host;
@@ -46,13 +47,8 @@ class AppStatusHook
     #[Hook('post_app_status')]
     public function postAppStatus(array $data): void
     {
-        try {
-            $this->httpClient->request('POST', '/php/app_status', [
-                'json' => $data
-            ]);
-        } catch (ClientException | TransportExceptionInterface $e) {
-            Log::error($e->getMessage());
-            Log::error(json_encode($e->getResponse()->toArray(false)));
-        }
+        $this->httpClient->request('POST', '/php/app_status', [
+            'json' => $data
+        ])->getContent();
     }
 }