From 0530306010dfe641774a007c19d3768fd179bc08 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Wed, 7 Sep 2022 15:57:06 +0800 Subject: [PATCH] =?UTF-8?q?API=E8=8A=82=E7=82=B9=E5=9C=A8=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=97=B6=E6=8F=90=E7=A4=BA=E2=80=9CAPI=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E6=AD=A3=E5=9C=A8=E5=90=AF=E5=8A=A8=EF=BC=8C=E8=AF=B7?= =?UTF-8?q?=E8=80=90=E5=BF=83=E7=AD=89=E5=BE=85=E5=AE=8C=E6=88=90=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/web/actions/actionutils/utils.go | 38 +++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/internal/web/actions/actionutils/utils.go b/internal/web/actions/actionutils/utils.go index a6597546..6797f6c6 100644 --- a/internal/web/actions/actionutils/utils.go +++ b/internal/web/actions/actionutils/utils.go @@ -11,6 +11,7 @@ import ( "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/logs" "github.com/iwind/TeaGo/maps" + "github.com/iwind/gosock/pkg/gosock" "net" "net/http" "os" @@ -18,6 +19,7 @@ import ( "reflect" "runtime" "strings" + "time" ) // Fail 提示服务器错误信息 @@ -45,6 +47,25 @@ func FailPage(action actions.ActionWrapper, err error) { var isRPCConnError bool err, isRPCConnError = rpcerrors.HumanError(err, apiEndpoints, Tea.ConfigFile("api.yaml")) + var apiNodeIsStarting = false + var apiNodeProgress = "" + if isRPCConnError { + // API节点是否正在启动 + var sock = gosock.NewTmpSock("edge-api") + reply, err := sock.SendTimeout(&gosock.Command{ + Code: "starting", + Params: nil, + }, 1*time.Second) + if err == nil && reply != nil { + var params = maps.NewMap(reply.Params) + if params.GetBool("isStarting") { + apiNodeIsStarting = true + + var progressMap = params.GetMap("progress") + apiNodeProgress = progressMap.GetString("description") + } + } + } action.Object().ResponseWriter.WriteHeader(http.StatusInternalServerError) if len(action.Object().Request.Header.Get("X-Requested-With")) > 0 { @@ -90,14 +111,25 @@ func FailPage(action actions.ActionWrapper, err error) {
- ` + teaconst.ErrServer + ` + ` + if apiNodeIsStarting { // API节点正在启动 + html += "
API节点正在启动,请耐心等待完成" + + if len(apiNodeProgress) > 0 { + html += ":" + apiNodeProgress + } + + html += "
" + } else { + html += teaconst.ErrServer + `
可以通过查看 $安装目录/logs/run.log 日志文件查看具体的错误提示。

Error: ` + err.Error() + `
` - if len(issuesHTML) > 0 { - html += `
+ if len(issuesHTML) > 0 { + html += `
` + issuesHTML + `
` + } } action.Object().WriteString(html + `