Commit 1a9f547d by zhengqiuyun86

初始化

parent fc0c8f31
......@@ -53,12 +53,10 @@ func getError(errs validator.ValidationErrors, r interface{}) string {
}
type DError struct {
Err string
Err string
Code string
}
func (e *DError) Error() string {
return e.Err
}
func ThrowsErrS(err string) {
if &err != nil && err != "" {
log.Error(err)
......@@ -72,9 +70,8 @@ func AssertThrowableErr(throwable bool, err error) {
panic(err)
}
}
func AssertThrowable(throwable bool, err string) {
func AssertThrowable(throwable bool, code, err string) {
if throwable {
log.Error(err)
panic(DError{Err: err})
panic(DError{Code: code, Err: err})
}
}
......@@ -4,9 +4,9 @@ import (
"fmt"
"git.168cad.top/zhengqiuyun/rym-util/exception"
"git.168cad.top/zhengqiuyun/rym-util/getWay"
"git.168cad.top/zhengqiuyun/rym-util/log"
"github.com/gin-gonic/gin"
"runtime"
"strings"
)
func ExceptionCatch(c *gin.Context) {
......@@ -15,17 +15,19 @@ func ExceptionCatch(c *gin.Context) {
switch err.(type) {
case exception.DError:
e := (err).(exception.DError)
getWay.FailAndMsg(c, e.Error())
if c == nil {
log.Error(fmt.Sprintf("%s-%s", e.Code, e.Err))
} else {
getWay.FailAndMsg(c, e.Code, e.Err)
}
break
case error:
e := (err).(error)
if strings.Index(e.Error(), "duplicate key") > 0 {
getWay.FailAndMsg(c, "信息重复")
} else {
var buf [1024]byte
n := runtime.Stack(buf[:], true)
fmt.Println(string(buf[:]), n)
getWay.FailAndMsg(c, e.Error())
var buf [1024]byte
n := runtime.Stack(buf[:], true)
fmt.Println(string(buf[:]), n)
if c != nil {
getWay.FailAndMsg(c, "SYSTEM.ERROR", e.Error())
}
break
}
......
......@@ -15,8 +15,10 @@ import (
)
type ServerResponse struct {
Code State `json:"code"` //0为成功,其他都是失败
Msg string `json:"msg,omitempty"` //非1000情况下的错误描述
Code State `json:"code"` //0为成功,其他都是失败
Msg string `json:"msg,omitempty"` //非1000情况下的错误描述
SubCode string `json:"subCode"`
SubMsg string `json:"subMsg"`
}
type ServerDataResponse struct {
......@@ -35,9 +37,9 @@ func FailGetWay(c *gin.Context, state State) {
logEnd(c, resp)
}
func FailAndMsg(c *gin.Context, msg string) {
func FailAndMsg(c *gin.Context, subCode, subMsg string) {
db.Rollback()
resp := ServerResponse{Code: BusinessError, Msg: msg}
resp := ServerResponse{Code: BusinessError, Msg: "业务错误", SubCode: subCode, SubMsg: subMsg}
c.JSON(http.StatusOK, resp)
c.Abort()
logEnd(c, resp)
......
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