Commit b7c45506 by zhengqiuyun86

初始化

parent 025e4980
package exception
import (
"errors"
"git.168cad.top/zhengqiuyun/rym-util/log"
"github.com/go-playground/validator/v10"
"reflect"
"strings"
)
func ThrowsErr(err error) {
if err != nil {
log.Error(err.Error())
panic(err)
}
panic(err)
}
func ThrowsValid(err error, r interface{}) {
......@@ -21,7 +16,7 @@ func ThrowsValid(err error, r interface{}) {
case validator.ValidationErrors:
e := (err).(validator.ValidationErrors)
errMsg := getError(e, r)
panic(errors.New(errMsg))
panic(DError{Code: "REQUEST_PARAMS_ERR", Err: errMsg})
break
default:
panic(err)
......@@ -57,21 +52,17 @@ type DError struct {
Code string
}
func ThrowsErrS(err string) {
if &err != nil && err != "" {
log.Error(err)
panic(DError{Err: err})
}
func ThrowsErrS(code, err string) {
panic(DError{Code: code, Err: err})
}
func AssertThrowableErr(throwable bool, err error) {
if throwable {
log.Error(err.Error())
panic(err)
ThrowsErr(err)
}
}
func AssertThrowable(throwable bool, code, err string) {
if throwable {
panic(DError{Code: code, Err: err})
ThrowsErrS(code, err)
}
}
......@@ -3,7 +3,9 @@ package getWay
import "github.com/gin-gonic/gin"
type Error struct {
Code State
Code State
SubCode string
SubMsg string
}
func ExceptionGetWayCatch(c *gin.Context) {
......@@ -12,20 +14,18 @@ func ExceptionGetWayCatch(c *gin.Context) {
switch err.(type) {
case Error:
e := (err).(Error)
FailGetWay(c, e.Code)
FailGetWay(c, e.Code, e.SubCode, e.SubMsg)
break
}
}
}
func ThrowsGetWayErr(code State) {
if &code != nil {
panic(Error{code})
}
func ThrowsGetWayErr(code State, subCode, subMsg string) {
panic(Error{Code: code, SubCode: subCode, SubMsg: subMsg})
}
func AssertThrowsGetWayErr(throwable bool, code State) {
func AssertThrowsGetWayErr(throwable bool, code State, subCode, subMsg string) {
if throwable {
panic(Error{code})
ThrowsGetWayErr(code, subCode, subMsg)
}
}
package getWay
import (
"git.168cad.top/zhengqiuyun/rym-util/exception"
"github.com/gin-gonic/gin"
)
......@@ -26,9 +25,6 @@ func SetToken(v string, c *gin.Context) {
func GetPlatformCode(c *gin.Context) string {
platformCode := getHeader(c, headerKeyPlatformCode)
if platformCode == "" {
exception.ThrowsErrS("平台错误")
}
return platformCode
}
......
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