1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-02-08 01:20:07 +08:00

feat: 版本更新检查错误信息优化 (#1273)

This commit is contained in:
ssongliu 2023-06-07 14:53:24 +08:00 committed by GitHub
parent e2a7c51de0
commit 4631da2212
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 6 deletions

View File

@ -2,7 +2,6 @@ package service
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
@ -12,6 +11,8 @@ import (
"time" "time"
"github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/buserr"
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/cmd" "github.com/1Panel-dev/1Panel/backend/utils/cmd"
"github.com/1Panel-dev/1Panel/backend/utils/common" "github.com/1Panel-dev/1Panel/backend/utils/common"
@ -204,12 +205,12 @@ func (u *UpgradeService) loadVersion(isLatest bool, currentVersion string) (stri
} }
latestVersionRes, err := http.Get(path) latestVersionRes, err := http.Get(path)
if err != nil { if err != nil {
return "", err return "", buserr.New(constant.ErrOSSConn)
} }
defer latestVersionRes.Body.Close() defer latestVersionRes.Body.Close()
version, err := io.ReadAll(latestVersionRes.Body) version, err := io.ReadAll(latestVersionRes.Body)
if err != nil { if err != nil {
return "", err return "", buserr.New(constant.ErrOSSConn)
} }
if isLatest { if isLatest {
return string(version), nil return string(version), nil
@ -217,7 +218,7 @@ func (u *UpgradeService) loadVersion(isLatest bool, currentVersion string) (stri
versionMap := make(map[string]string) versionMap := make(map[string]string)
if err := json.Unmarshal(version, &versionMap); err != nil { if err := json.Unmarshal(version, &versionMap); err != nil {
return "", fmt.Errorf("load version map failed, err: %v", err) return "", buserr.New(constant.ErrOSSConn)
} }
if len(currentVersion) < 4 { if len(currentVersion) < 4 {
@ -226,7 +227,7 @@ func (u *UpgradeService) loadVersion(isLatest bool, currentVersion string) (stri
if version, ok := versionMap[currentVersion[0:4]]; ok { if version, ok := versionMap[currentVersion[0:4]]; ok {
return version, nil return version, nil
} }
return "", errors.New("load version failed in latest.current") return "", buserr.New(constant.ErrOSSConn)
} }
func (u *UpgradeService) loadReleaseNotes(path string) (string, error) { func (u *UpgradeService) loadReleaseNotes(path string) (string, error) {

View File

@ -118,4 +118,5 @@ var (
var ( var (
ErrBackupInUsed = "ErrBackupInUsed" ErrBackupInUsed = "ErrBackupInUsed"
ErrOSSConn = "ErrOSSConn"
) )

View File

@ -88,3 +88,5 @@ ErrDelWithWebsite: "The operating environment has been associated with a website
#setting #setting
ErrBackupInUsed: "The backup account is already being used in a cronjob and cannot be deleted." ErrBackupInUsed: "The backup account is already being used in a cronjob and cannot be deleted."
ErrOSSConn: "Unable to successfully request the latest version. Please check if the server can connect to the external network environment."

View File

@ -88,3 +88,5 @@ ErrDelWithWebsite: "运行环境已经关联网站,无法删除"
#setting #setting
ErrBackupInUsed: "该备份账号已在计划任务中使用,无法删除" ErrBackupInUsed: "该备份账号已在计划任务中使用,无法删除"
ErrOSSConn: "无法成功请求最新版本,请检查服务器是否能够连接到外部网络环境。"