package actionutils import ( "errors" "fmt" rpcerrors "github.com/TeaOSLab/EdgeCommon/pkg/rpc/errors" "github.com/TeaOSLab/EdgeUser/internal/configs" teaconst "github.com/TeaOSLab/EdgeUser/internal/const" "github.com/iwind/TeaGo/Tea" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/logs" "net/http" "os" "path/filepath" "reflect" "runtime" "strings" ) // Fail 提示服务器错误信息 func Fail(action actions.ActionWrapper, err error) { if err != nil { logs.Println("[" + reflect.TypeOf(action).String() + "]" + findStack(err.Error())) } action.Object().Fail(teaconst.ErrServer + "(请查看日志文件以获取具体信息)") } // FailPage 提示页面错误信息 func FailPage(action actions.ActionWrapper, err error) { if err == nil { err = errors.New("unknown error") } logs.Println("[" + reflect.TypeOf(action).String() + "]" + findStack(err.Error())) // 当前API终端地址 var apiEndpoints = []string{} apiConfig, apiConfigErr := configs.LoadAPIConfig() if apiConfigErr == nil && apiConfig != nil { apiEndpoints = append(apiEndpoints, apiConfig.RPCEndpoints...) } err, _ = rpcerrors.HumanError(err, apiEndpoints, Tea.ConfigFile(configs.ConfigFileName)) action.Object().ResponseWriter.WriteHeader(http.StatusInternalServerError) if len(action.Object().Request.Header.Get("X-Requested-With")) > 0 { action.Object().WriteString(teaconst.ErrServer) } else { action.Object().WriteString(`