fix nested tcc bug
This commit is contained in:
parent
94e8e4eff9
commit
f4796ec474
@ -139,7 +139,9 @@ func WrapHandler(fn func(*gin.Context) (interface{}, error)) gin.HandlerFunc {
|
|||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
r, err := fn(c)
|
r, err := fn(c)
|
||||||
var b = []byte{}
|
var b = []byte{}
|
||||||
if err == nil {
|
if resp, ok := r.(*resty.Response); ok { // 如果是response,则取出body直接处理
|
||||||
|
b = resp.Body()
|
||||||
|
} else if err == nil {
|
||||||
b, err = json.Marshal(r)
|
b, err = json.Marshal(r)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -83,7 +83,7 @@ func (t *Tcc) CallBranch(body interface{}, tryURL string, confirmURL string, can
|
|||||||
if IsFailure(resp, err) {
|
if IsFailure(resp, err) {
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
resp, err = common.RestyClient.R().
|
return common.RestyClient.R().
|
||||||
SetBody(body).
|
SetBody(body).
|
||||||
SetQueryParams(common.MS{
|
SetQueryParams(common.MS{
|
||||||
"dtm": t.Dtm,
|
"dtm": t.Dtm,
|
||||||
@ -93,5 +93,4 @@ func (t *Tcc) CallBranch(body interface{}, tryURL string, confirmURL string, can
|
|||||||
"branch_type": "try",
|
"branch_type": "try",
|
||||||
}).
|
}).
|
||||||
Post(tryURL)
|
Post(tryURL)
|
||||||
return resp, err
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,13 +21,13 @@ func MustGenGid(server string) string {
|
|||||||
// IsFailure 如果err非空,或者ret是http的响应且包含FAILURE,那么返回true。此时认为业务调用失败
|
// IsFailure 如果err非空,或者ret是http的响应且包含FAILURE,那么返回true。此时认为业务调用失败
|
||||||
func IsFailure(res interface{}, err error) bool {
|
func IsFailure(res interface{}, err error) bool {
|
||||||
resp, ok := res.(*resty.Response)
|
resp, ok := res.(*resty.Response)
|
||||||
return err != nil || ok && strings.Contains(resp.String(), "FAILURE")
|
return err != nil || ok && (strings.Contains(resp.String(), "FAILURE") || resp.IsError())
|
||||||
}
|
}
|
||||||
|
|
||||||
// PanicIfFailure 如果err非空,或者ret是http的响应且包含FAILURE,那么Panic。此时认为业务调用失败
|
// PanicIfFailure 如果err非空,或者ret是http的响应且包含FAILURE,那么Panic。此时认为业务调用失败
|
||||||
func PanicIfFailure(res interface{}, err error) {
|
func PanicIfFailure(res interface{}, err error) {
|
||||||
resp, ok := res.(*resty.Response)
|
resp, ok := res.(*resty.Response)
|
||||||
failure := err != nil || ok && strings.Contains(resp.String(), "FAILURE")
|
failure := err != nil || ok && (strings.Contains(resp.String(), "FAILURE") || resp.IsError())
|
||||||
if failure {
|
if failure {
|
||||||
panic(fmt.Errorf("dtm failure ret: %v err %v", res, err))
|
panic(fmt.Errorf("dtm failure ret: %v err %v", res, err))
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ func CheckDtmResponse(resp *resty.Response, err error) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !strings.Contains(resp.String(), "SUCCESS") {
|
if !strings.Contains(resp.String(), "SUCCESS") || resp.IsError() {
|
||||||
return fmt.Errorf("dtm response failed: %s", resp.String())
|
return fmt.Errorf("dtm response failed: %s", resp.String())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -9,12 +9,12 @@ import (
|
|||||||
func TestExamples(t *testing.T) {
|
func TestExamples(t *testing.T) {
|
||||||
// for coverage
|
// for coverage
|
||||||
examples.QsStartSvr()
|
examples.QsStartSvr()
|
||||||
// assertSucceed(t, examples.QsFireRequest())
|
assertSucceed(t, examples.QsFireRequest())
|
||||||
// assertSucceed(t, examples.MsgFireRequest())
|
assertSucceed(t, examples.MsgFireRequest())
|
||||||
assertSucceed(t, examples.SagaBarrierFireRequest())
|
assertSucceed(t, examples.SagaBarrierFireRequest())
|
||||||
// assertSucceed(t, examples.SagaFireRequest())
|
assertSucceed(t, examples.SagaFireRequest())
|
||||||
// assertSucceed(t, examples.TccBarrierFireRequest())
|
assertSucceed(t, examples.TccBarrierFireRequest())
|
||||||
// assertSucceed(t, examples.TccFireRequest())
|
assertSucceed(t, examples.TccFireRequest())
|
||||||
// assertSucceed(t, examples.TccFireRequestNested())
|
assertSucceed(t, examples.TccFireRequestNested())
|
||||||
// assertSucceed(t, examples.XaFireRequest())
|
assertSucceed(t, examples.XaFireRequest())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,9 +13,7 @@ func TccSetup(app *gin.Engine) {
|
|||||||
tcc, err := dtmcli.TccFromReq(c)
|
tcc, err := dtmcli.TccFromReq(c)
|
||||||
e2p(err)
|
e2p(err)
|
||||||
logrus.Printf("TransInTccParent ")
|
logrus.Printf("TransInTccParent ")
|
||||||
_, rerr := tcc.CallBranch(&TransReq{Amount: reqFrom(c).Amount}, Busi+"/TransIn", Busi+"/TransInConfirm", Busi+"/TransInRevert")
|
return tcc.CallBranch(&TransReq{Amount: reqFrom(c).Amount}, Busi+"/TransIn", Busi+"/TransInConfirm", Busi+"/TransInRevert")
|
||||||
e2p(rerr)
|
|
||||||
return M{"dtm_result": "SUCCESS"}, nil
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user