Commit b7c45506 by zhengqiuyun86

初始化

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