Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gomicro-base
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
lizifeng
gomicro-base
Commits
5205d2de
Commit
5205d2de
authored
Jun 10, 2022
by
kzkzzzz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 修改错误
parent
69953656
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
12 deletions
+21
-12
error.go
common/errorx/error.go
+21
-12
No files found.
common/errorx/error.go
View file @
5205d2de
...
@@ -6,11 +6,20 @@ import (
...
@@ -6,11 +6,20 @@ import (
"gomicro-base/common/validate"
"gomicro-base/common/validate"
)
)
type
code
int32
const
(
const
(
DefaultError
=
500
DefaultErrorCode
int32
=
1000
ParamsError
=
400
ParamsErrorCode
=
1001
NotFoundErrorCode
=
1002
)
)
var
codeStatusText
=
map
[
int32
]
string
{
DefaultErrorCode
:
"操作失败"
,
ParamsErrorCode
:
"参数不正确"
,
NotFoundErrorCode
:
"未查询到记录"
,
}
type
ResponseError
struct
{
type
ResponseError
struct
{
Code
int
`json:"code"`
Code
int
`json:"code"`
Msg
string
`json:"msg"`
Msg
string
`json:"msg"`
...
@@ -22,22 +31,22 @@ func (c *ResponseError) Error() string {
...
@@ -22,22 +31,22 @@ func (c *ResponseError) Error() string {
return
fmt
.
Sprintf
(
"[%d]%s"
,
c
.
Code
,
c
.
Msg
)
return
fmt
.
Sprintf
(
"[%d]%s"
,
c
.
Code
,
c
.
Msg
)
}
}
func
NewMicroError
(
detail
string
,
code
...
int
)
error
{
func
NewMicroError
(
detail
string
,
code
...
int
32
)
error
{
var
c
=
DefaultError
var
c
=
DefaultError
Code
if
len
(
code
)
>
0
{
if
len
(
code
)
>
0
{
c
=
code
[
0
]
c
=
code
[
0
]
}
}
return
&
errors
.
Error
{
return
&
errors
.
Error
{
Code
:
int32
(
c
)
,
Code
:
c
,
Detail
:
detail
,
Detail
:
detail
,
Status
:
"操作失败"
,
Status
:
codeStatusText
[
c
]
,
}
}
}
}
func
New
ParamsError
(
err
error
)
error
{
func
Trans
ParamsError
(
err
error
)
error
{
return
&
errors
.
Error
{
return
NewMicroError
(
validate
.
TransError
(
err
),
ParamsErrorCode
)
Code
:
int32
(
ParamsError
),
}
Detail
:
validate
.
TransError
(
err
),
Status
:
"参数不正确"
,
func
NotFound
(
detail
string
)
error
{
}
return
NewMicroError
(
detail
,
NotFoundErrorCode
)
}
}
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