2
0
Эх сурвалжийг харах

添加错误处理 没有找到book uid

visuddhinanda 1 сар өмнө
parent
commit
af8af1f1e2

+ 12 - 2
api-v12/app/Services/PaliTextService.php

@@ -3,6 +3,7 @@
 namespace App\Services;
 
 use App\Models\PaliText;
+use Illuminate\Support\Facades\Log;
 
 class PaliTextService
 {
@@ -28,13 +29,22 @@ class PaliTextService
         if ($paragraph) {
             return $paragraph;
         } else {
+            Log::error('not found book ', ['book' => $book, 'para' => $para]);
             return null;
         }
     }
-    public function getParaCategoryTags(int $book, int $para)
+    public function getParaCategoryTags(int $book, int $para): array
     {
         $bookPara = self::getBookPara($book, $para);
-        return app(TagService::class)->getTagsName($bookPara->uid);
+        if (!$bookPara) {
+            return [];
+        }
+        if (isset($bookPara->uid) && $bookPara->uid) {
+            return app(TagService::class)->getTagsName($bookPara->uid);
+        } else {
+            Log::error('book uid is null', ['book' => $book, 'para' => $para]);
+            return [];
+        }
     }
     public function getParaInfo(int $book, int $para)
     {

+ 1 - 1
api-v12/app/Services/TagService.php

@@ -6,7 +6,7 @@ use App\Models\TagMap;
 
 class TagService
 {
-    public function getTagsName(string $resId)
+    public function getTagsName(string $resId): array
     {
         $tagsName = TagMap::where('table_name', 'pali_texts')
             ->where('anchor_id', $resId)