فهرست منبع

refactor(sixshop-core):扩展 NotFoundException 构造函数参数类型,支持传入字符串

runphp 6 ماه پیش
والد
کامیت
47e55eb00c
1فایلهای تغییر یافته به همراه8 افزوده شده و 2 حذف شده
  1. 8 2
      src/Exception/NotFoundException.php

+ 8 - 2
src/Exception/NotFoundException.php

@@ -1,4 +1,5 @@
 <?php
+declare(strict_types=1);
 
 namespace SixShop\Core\Exception;
 
@@ -8,8 +9,13 @@ use function SixShop\Core\error_response;
 
 class NotFoundException extends HttpResponseException
 {
-    public function __construct(Exception $e)
+    public function __construct(Exception|string $e)
     {
-        parent::__construct(error_response(msg:$e->getMessage(),  status: 'not_found', code: 404, httpCode: 200));
+        if (is_string($e)) {
+            $msg = $e;
+        } else {
+            $msg = $e->getMessage();
+        }
+        parent::__construct(error_response(msg: $msg, status: 'not_found', code: 404, httpCode: 200));
     }
 }