mirror of https://github.com/1Panel-dev/1Panel
feat: 版本更新检查错误信息优化 (#1273)
parent
e2a7c51de0
commit
4631da2212
|
@ -2,7 +2,6 @@ package service
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
@ -12,6 +11,8 @@ import (
|
|||
"time"
|
||||
|
||||
"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/utils/cmd"
|
||||
"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)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", buserr.New(constant.ErrOSSConn)
|
||||
}
|
||||
defer latestVersionRes.Body.Close()
|
||||
version, err := io.ReadAll(latestVersionRes.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", buserr.New(constant.ErrOSSConn)
|
||||
}
|
||||
if isLatest {
|
||||
return string(version), nil
|
||||
|
@ -217,7 +218,7 @@ func (u *UpgradeService) loadVersion(isLatest bool, currentVersion string) (stri
|
|||
|
||||
versionMap := make(map[string]string)
|
||||
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 {
|
||||
|
@ -226,7 +227,7 @@ func (u *UpgradeService) loadVersion(isLatest bool, currentVersion string) (stri
|
|||
if version, ok := versionMap[currentVersion[0:4]]; ok {
|
||||
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) {
|
||||
|
|
|
@ -118,4 +118,5 @@ var (
|
|||
|
||||
var (
|
||||
ErrBackupInUsed = "ErrBackupInUsed"
|
||||
ErrOSSConn = "ErrOSSConn"
|
||||
)
|
||||
|
|
|
@ -87,4 +87,6 @@ ErrImageExist: "Image is already exist!"
|
|||
ErrDelWithWebsite: "The operating environment has been associated with a website and cannot be deleted"
|
||||
|
||||
#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."
|
|
@ -88,3 +88,5 @@ ErrDelWithWebsite: "运行环境已经关联网站,无法删除"
|
|||
|
||||
#setting
|
||||
ErrBackupInUsed: "该备份账号已在计划任务中使用,无法删除"
|
||||
|
||||
ErrOSSConn: "无法成功请求最新版本,请检查服务器是否能够连接到外部网络环境。"
|
||||
|
|
Loading…
Reference in New Issue