瀏覽代碼

feat(core): 增强LogicException类以支持状态码获取

- 添加了$status私有属性用于存储响应状态
- 修改构造函数以从响应数据中提取状态和消息
- 新增getStatus方法用于获取异常状态码
- 更新异常消息来源为响应数据中的msg字段
- 保持与HttpResponseException的继承关系不变
runphp 5 月之前
父節點
當前提交
03415d7949
共有 1 個文件被更改,包括 7 次插入1 次删除
  1. 7 1
      src/Exception/LogicException.php

+ 7 - 1
src/Exception/LogicException.php

@@ -8,9 +8,15 @@ use think\Response;
 
 class LogicException extends HttpResponseException
 {
+    private string $status;
     public function __construct(protected Response $response)
     {
         parent::__construct($response);
-        $this->message = $response->getContent();
+        $this->message = $response->getData()['msg'];
+        $this->status = $response->getData()['status'];
+    }
+    public function getStatus(): string
+    {
+        return $this->status;
     }
 }