Przeglądaj źródła

fix(wechat): 优化快递公司获取和订单状态查询的错误处理

- 调整代码格式,增加空行提升可读性
- 修复字符串拼接中的空格问题
- 在查询订单发货状态时,记录完整的响应数据到日志
- 抛出逻辑异常时携带微信返回的具体错误码
runphp 4 miesięcy temu
rodzic
commit
6160f17af8
1 zmienionych plików z 5 dodań i 3 usunięć
  1. 5 3
      src/Service/ExpressService.php

+ 5 - 3
src/Service/ExpressService.php

@@ -1,5 +1,6 @@
 <?php
 declare(strict_types=1);
+
 namespace SixShop\Wechat\Service;
 
 use SixShop\Wechat\Entity\WechatDeliveryEntity;
@@ -22,7 +23,7 @@ class ExpressService
         if ($result->isEmpty()) {
             $response = $this->miniApp->getClient()->get('/cgi-bin/express/business/delivery/getall');
             if ($response->isFailed()) {
-                Log::error('获取所有快递公司失败'.json_encode($response->toArray()));
+                Log::error('获取所有快递公司失败' . json_encode($response->toArray()));
                 throw_logic_exception('获取所有快递公司失败');
             }
             $result = $response->toArray();
@@ -42,8 +43,9 @@ class ExpressService
             'transaction_id' => $transactionID,
         ]);
         if ($response->isFailed()) {
-            Log::error('查询订单发货状态失败{transaction_id}{response}', ['transaction_id' => $transactionID, 'response' => $response->toArray()]);
-            throw_logic_exception('查询订单发货状态失败');
+            $responseData = $response->toArray();
+            Log::error('查询订单发货状态失败{transaction_id}{response}', ['transaction_id' => $transactionID, 'response' => json_encode($responseData)]);
+            throw_logic_exception(msg: '查询订单发货状态失败', status: $responseData['errcode']);
         }
         return $response->toArray()['order'];
     }