Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb654ad3

Browse files
committed
## 0.2.0-beta10 fix some
1 parentdecda6d commitb654ad3

File tree

9 files changed

+66
-25
lines changed

9 files changed

+66
-25
lines changed

‎action/action.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ func New(ctx context.Context, actionConfig *config.ActionConfig, method string,
4848

4949
request,err:=checkTag(req,method,actionConfig)
5050
iferr!=nil {
51-
panic(err)
51+
return&Action{
52+
err:err,
53+
}
5254
}
5355

5456
delete(req,consts.Tag)
@@ -68,6 +70,10 @@ func New(ctx context.Context, actionConfig *config.ActionConfig, method string,
6870

6971
func (a*Action)parse()error {
7072

73+
ifa.err!=nil {
74+
returna.err
75+
}
76+
7177
structures:=a.tagRequest.Structure
7278

7379
forkey,v:=rangea.req {
@@ -138,10 +144,9 @@ func (a *Action) Result() (model.Map, error) {
138144

139145
transactionHandler:=noTransactionHandler
140146

141-
if*a.tagRequest.Transaction==true {
142-
transactionResolver=GetTransactionHandler
143-
h:=transactionResolver(a.ctx,a)
144-
ifh!=nil {
147+
ifa.tagRequest.Transaction!=nil&&*a.tagRequest.Transaction==true {
148+
h:=GetTransactionHandler(a.ctx,a)
149+
ifh==nil {
145150
err=consts.NewSysErr("transaction handler is nil")
146151
returnnil,err
147152
}

‎config/action_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (c *ActionConfig) GetAccessConfig(key string, noVerify bool) (*AccessConfig
2626
returnc.access.GetAccess(key,noVerify)
2727
}
2828

29-
func (c*ActionConfig)Func(namestring)Func {
29+
func (c*ActionConfig)Func(namestring)*Func {
3030
returnc.functions.funcMap[name]
3131
}
3232

‎config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func New() *Config {
7171
a.JsonFieldStyle=CaseCamel
7272

7373
a.Functions=&functions{}
74-
a.Functions.funcMap=make(map[string]Func)
74+
a.Functions.funcMap=make(map[string]*Func)
7575

7676
returna
7777
}

‎config/functions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ type Func struct {
2121
}
2222

2323
typefunctionsstruct {
24-
funcMapmap[string]Func
24+
funcMapmap[string]*Func
2525
}
2626

2727
func (f*functions)Bind(namestring,_funcFunc) {
2828
if_,exists:=f.funcMap[name];exists {
2929
panic(fmt.Errorf(" function %s has exists",name))
3030
}
31-
f.funcMap[name]=_func
31+
f.funcMap[name]=&_func
3232
}
3333

3434
func (f*functions)Call(ctx context.Context,namestring,param g.Map) (any,error) {

‎config/query_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (c *QueryConfig) GetAccessConfig(key string, noVerify bool) (*AccessConfig,
2626
returnc.access.GetAccess(key,noVerify)
2727
}
2828

29-
func (c*QueryConfig)Func(namestring)Func {
29+
func (c*QueryConfig)Func(namestring)*Func {
3030
returnc.functions.funcMap[name]
3131
}
3232

‎config/request_config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"strings"
55

66
"github.com/glennliao/apijson-go/consts"
7-
"github.com/gogf/gf/v2/errors/gerror"
87
"github.com/gogf/gf/v2/frame/g"
98
"github.com/gogf/gf/v2/os/gtime"
109
"github.com/gogf/gf/v2/util/gconv"
@@ -84,7 +83,7 @@ func (c *RequestConfigs) GetRequest(tag string, method string, version string) (
8483
request,ok:=c.requestMap[key]
8584

8685
if!ok {
87-
returnnil,gerror.Newf("request[%s]: 404",key)
86+
returnnil,consts.NewRequestNoFoundErr(key)
8887
}
8988

9089
returnrequest,nil

‎consts/errors.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ func NewAccessNoFoundErr(key string) Err {
5757
}
5858
}
5959

60+
funcNewRequestNoFoundErr(keystring)Err {
61+
returnErr{
62+
code:404,
63+
message:"request no found: "+key,
64+
}
65+
}
66+
6067
funcNewSysErr(msgstring)Err {
6168
returnErr{
6269
code:500,

‎drivers/goframe/web/gf.go

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"net/http"
7+
"strconv"
78
"strings"
89
"time"
910

@@ -107,14 +108,33 @@ func sortMap(ctx context.Context, body []byte, res *gmap.ListMap, ret model.Map)
107108
returnreqSortMap
108109
}
109110

111+
functry(ctx context.Context,tryfunc(ctx context.Context)error) (errerror) {
112+
deferfunc() {
113+
ifexception:=recover();exception!=nil {
114+
ifv,ok:=exception.(error);ok&&gerror.HasStack(v) {
115+
err=v
116+
}else {
117+
err=gerror.Newf(`%+v`,exception)
118+
}
119+
}
120+
}()
121+
err=try(ctx)
122+
return
123+
}
124+
125+
typeCodeErrinterface {
126+
Code()int
127+
Error()string
128+
}
129+
110130
funcCommonResponse(handlerfunc(ctx context.Context,req model.Map) (res model.Map,errerror),modeMode,debugbool)func(req*ghttp.Request) {
111131
returnfunc(req*ghttp.Request) {
112132
metaRes:=&gmap.ListMap{}
113133
code:=200
114134
msg:="success"
115135
nodeRes:=&gmap.ListMap{}
116136

117-
err:=g.Try(req.Context(),func(ctx context.Context) {
137+
err:=try(req.Context(),func(ctx context.Context) (errerror) {
118138

119139
ret,err:=handler(ctx,req.GetMap())
120140

@@ -125,28 +145,33 @@ func CommonResponse(handler func(ctx context.Context, req model.Map) (res model.
125145
nodeRes.Set(k,v)
126146
}
127147
}
128-
129-
iferr!=nil {
130-
panic(err)
131-
}
132-
148+
return
133149
})
134150

135151
iferr!=nil {
136152

137-
ife,ok:=err.(consts.Err);ok {
153+
ife,ok:=err.(CodeErr);ok {
138154
code=e.Code()
155+
ifstrconv.Itoa(e.Code())[0]=='4' {
156+
code=e.Code()
157+
msg=e.Error()
158+
}else {
159+
code=500
160+
msg="系统异常"
161+
}
139162
}else {
140163
code=500
164+
msg="系统异常"
141165
}
142166

143-
msg=err.Error()
144-
145-
ife,ok:=err.(*gerror.Error);ok {
146-
g.Log().Stack(false).Error(req.Context(),err,e.Stack())
147-
}else {
148-
g.Log().Stack(false).Error(req.Context(),err)
167+
ifcode>=500 {
168+
ife,ok:=err.(*gerror.Error);ok {
169+
g.Log().Stack(false).Error(req.Context(),err,e.Stack())
170+
}else {
171+
g.Log().Stack(false).Error(req.Context(),err)
172+
}
149173
}
174+
150175
}
151176

152177
metaRes.Set("ok",code==200)

‎query/node_func.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ func (h *funcNode) result() {
3434

3535
_func:=queryConfig.Func(functionName)
3636

37+
if_func==nil {
38+
n.err=consts.NewValidReqErr("functions not exists: "+functionName)
39+
return
40+
}
41+
3742
ifn.isList&&_func.Batch {
3843
n.later=true
3944
return

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp