Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rym-util
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhengqiuyun
rym-util
Commits
1a9f547d
Commit
1a9f547d
authored
Aug 17, 2022
by
zhengqiuyun86
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
初始化
parent
fc0c8f31
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
20 deletions
+21
-20
GlobalException.go
exception/GlobalException.go
+4
-7
CatchException.go
exception/catch/CatchException.go
+11
-9
Response.go
getWay/Response.go
+6
-4
No files found.
exception/GlobalException.go
View file @
1a9f547d
...
@@ -53,12 +53,10 @@ func getError(errs validator.ValidationErrors, r interface{}) string {
...
@@ -53,12 +53,10 @@ func getError(errs validator.ValidationErrors, r interface{}) string {
}
}
type
DError
struct
{
type
DError
struct
{
Err
string
Err
string
Code
string
}
}
func
(
e
*
DError
)
Error
()
string
{
return
e
.
Err
}
func
ThrowsErrS
(
err
string
)
{
func
ThrowsErrS
(
err
string
)
{
if
&
err
!=
nil
&&
err
!=
""
{
if
&
err
!=
nil
&&
err
!=
""
{
log
.
Error
(
err
)
log
.
Error
(
err
)
...
@@ -72,9 +70,8 @@ func AssertThrowableErr(throwable bool, err error) {
...
@@ -72,9 +70,8 @@ func AssertThrowableErr(throwable bool, err error) {
panic
(
err
)
panic
(
err
)
}
}
}
}
func
AssertThrowable
(
throwable
bool
,
err
string
)
{
func
AssertThrowable
(
throwable
bool
,
code
,
err
string
)
{
if
throwable
{
if
throwable
{
log
.
Error
(
err
)
panic
(
DError
{
Code
:
code
,
Err
:
err
})
panic
(
DError
{
Err
:
err
})
}
}
}
}
exception/catch/CatchException.go
View file @
1a9f547d
...
@@ -4,9 +4,9 @@ import (
...
@@ -4,9 +4,9 @@ import (
"fmt"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util/exception"
"git.168cad.top/zhengqiuyun/rym-util/exception"
"git.168cad.top/zhengqiuyun/rym-util/getWay"
"git.168cad.top/zhengqiuyun/rym-util/getWay"
"git.168cad.top/zhengqiuyun/rym-util/log"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"runtime"
"runtime"
"strings"
)
)
func
ExceptionCatch
(
c
*
gin
.
Context
)
{
func
ExceptionCatch
(
c
*
gin
.
Context
)
{
...
@@ -15,17 +15,19 @@ func ExceptionCatch(c *gin.Context) {
...
@@ -15,17 +15,19 @@ func ExceptionCatch(c *gin.Context) {
switch
err
.
(
type
)
{
switch
err
.
(
type
)
{
case
exception
.
DError
:
case
exception
.
DError
:
e
:=
(
err
)
.
(
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
break
case
error
:
case
error
:
e
:=
(
err
)
.
(
error
)
e
:=
(
err
)
.
(
error
)
if
strings
.
Index
(
e
.
Error
(),
"duplicate key"
)
>
0
{
var
buf
[
1024
]
byte
getWay
.
FailAndMsg
(
c
,
"信息重复"
)
n
:=
runtime
.
Stack
(
buf
[
:
],
true
)
}
else
{
fmt
.
Println
(
string
(
buf
[
:
]),
n
)
var
buf
[
1024
]
byte
if
c
!=
nil
{
n
:=
runtime
.
Stack
(
buf
[
:
],
true
)
getWay
.
FailAndMsg
(
c
,
"SYSTEM.ERROR"
,
e
.
Error
())
fmt
.
Println
(
string
(
buf
[
:
]),
n
)
getWay
.
FailAndMsg
(
c
,
e
.
Error
())
}
}
break
break
}
}
...
...
getWay/Response.go
View file @
1a9f547d
...
@@ -15,8 +15,10 @@ import (
...
@@ -15,8 +15,10 @@ import (
)
)
type
ServerResponse
struct
{
type
ServerResponse
struct
{
Code
State
`json:"code"`
//0为成功,其他都是失败
Code
State
`json:"code"`
//0为成功,其他都是失败
Msg
string
`json:"msg,omitempty"`
//非1000情况下的错误描述
Msg
string
`json:"msg,omitempty"`
//非1000情况下的错误描述
SubCode
string
`json:"subCode"`
SubMsg
string
`json:"subMsg"`
}
}
type
ServerDataResponse
struct
{
type
ServerDataResponse
struct
{
...
@@ -35,9 +37,9 @@ func FailGetWay(c *gin.Context, state State) {
...
@@ -35,9 +37,9 @@ func FailGetWay(c *gin.Context, state State) {
logEnd
(
c
,
resp
)
logEnd
(
c
,
resp
)
}
}
func
FailAndMsg
(
c
*
gin
.
Context
,
m
sg
string
)
{
func
FailAndMsg
(
c
*
gin
.
Context
,
subCode
,
subM
sg
string
)
{
db
.
Rollback
()
db
.
Rollback
()
resp
:=
ServerResponse
{
Code
:
BusinessError
,
Msg
:
m
sg
}
resp
:=
ServerResponse
{
Code
:
BusinessError
,
Msg
:
"业务错误"
,
SubCode
:
subCode
,
SubMsg
:
subM
sg
}
c
.
JSON
(
http
.
StatusOK
,
resp
)
c
.
JSON
(
http
.
StatusOK
,
resp
)
c
.
Abort
()
c
.
Abort
()
logEnd
(
c
,
resp
)
logEnd
(
c
,
resp
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment