Commit 94b04f23 by zhengqiuyun86

网络通过

parent 3e92c9d9
......@@ -8,6 +8,12 @@ type Error struct {
SubMsg string
}
type SError struct {
Code State
SubCode string
SubMsg string
}
func ExceptionGetWayCatch(c *gin.Context) {
err := recover() //获取异常
if err != nil {
......@@ -16,6 +22,10 @@ func ExceptionGetWayCatch(c *gin.Context) {
e := (err).(Error)
FailGetWay(c, e.Code, e.SubCode, e.SubMsg)
break
case SError:
e := (err).(Error)
SuccessGetWay(c, e.Code, e.SubCode, e.SubMsg)
break
}
}
}
......@@ -24,8 +34,18 @@ func ThrowsGetWayErr(code State, subCode, subMsg string) {
panic(Error{Code: code, SubCode: subCode, SubMsg: subMsg})
}
func ThrowsGetWaySErr(code State, subCode, subMsg string) {
panic(SError{Code: code, SubCode: subCode, SubMsg: subMsg})
}
func AssertThrowsGetWayErr(throwable bool, code State, subCode, subMsg string) {
if throwable {
ThrowsGetWayErr(code, subCode, subMsg)
}
}
func AssertThrowsGetWaySErr(throwable bool, code State, subCode, subMsg string) {
if throwable {
ThrowsGetWaySErr(code, subCode, subMsg)
}
}
......@@ -41,6 +41,13 @@ func FailGetWay(c *gin.Context, state State, subCode, subMsg string) {
LogEnd(c, resp)
}
func SuccessGetWay(c *gin.Context, state State, subCode, subMsg string) {
resp := responseSub(state, subCode, subMsg)
c.JSON(http.StatusOK, resp)
c.Abort()
LogEnd(c, resp)
}
func FailAndMsg(c *gin.Context, subCode, subMsg string) {
db.Rollback()
resp := ServerResponse{Code: BusinessError, Msg: "业务错误", SubCode: subCode, SubMsg: subMsg}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment