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
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
14 deletions
+15
-14
GlobalException.go
exception/GlobalException.go
+3
-6
CatchException.go
exception/catch/CatchException.go
+8
-6
Response.go
getWay/Response.go
+4
-2
No files found.
exception/GlobalException.go
View file @
1a9f547d
...
...
@@ -54,11 +54,9 @@ func getError(errs validator.ValidationErrors, r interface{}) string {
type
DError
struct
{
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
})
}
}
exception/catch/CatchException.go
View file @
1a9f547d
...
...
@@ -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
())
if
c
!=
nil
{
getWay
.
FailAndMsg
(
c
,
"SYSTEM.ERROR"
,
e
.
Error
())
}
break
}
...
...
getWay/Response.go
View file @
1a9f547d
...
...
@@ -17,6 +17,8 @@ import (
type
ServerResponse
struct
{
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
,
m
sg
string
)
{
func
FailAndMsg
(
c
*
gin
.
Context
,
subCode
,
subM
sg
string
)
{
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
.
Abort
()
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