فهرست منبع

优化:下载用户头像失败时报错

Yahoo 4 سال پیش
والد
کامیت
78efbf652a
2فایلهای تغییر یافته به همراه14 افزوده شده و 13 حذف شده
  1. 4 0
      app/api/service/passport/Party.php
  2. 10 13
      app/api/service/user/Avatar.php

+ 4 - 0
app/api/service/passport/Party.php

@@ -95,6 +95,8 @@ class Party extends BaseService
      * @param array $partyData 第三方用户信息
      * @param bool $isGetAvatarUrl 是否下载头像
      * @return array
+     * @throws BaseException
+     * @throws \think\Exception
      */
     public static function partyUserInfo(array $partyData, bool $isGetAvatarUrl = true): array
     {
@@ -114,6 +116,8 @@ class Party extends BaseService
      * 下载第三方头像并写入文件库
      * @param string $avatarUrl
      * @return int
+     * @throws BaseException
+     * @throws \think\Exception
      */
     private static function partyAvatar(string $avatarUrl): int
     {

+ 10 - 13
app/api/service/user/Avatar.php

@@ -46,21 +46,18 @@ class Avatar extends BaseService
     /**
      * 下载第三方头像并返回文件记录ID
      * @param string $avatarUrl
-     * @return int|false
+     * @return int
+     * @throws BaseException
+     * @throws \think\Exception
      */
-    public function party(string $avatarUrl)
+    public function party(string $avatarUrl): int
     {
-        try {
-            // 下载网络图片
-            $filePath = $this->download($avatarUrl);
-            // 上传到本地
-            $fileInfo = $this->upload($filePath);
-            // 新增文件记录
-            return $this->record($fileInfo);
-        } catch (\Exception $e) {
-            $this->error = $e->getMessage();
-            return false;
-        }
+        // 下载网络图片
+        $filePath = $this->download($avatarUrl);
+        // 上传到本地
+        $fileInfo = $this->upload($filePath);
+        // 新增文件记录
+        return $this->record($fileInfo);
     }
 
     /**