Skip to content

Commit 883a90e

Browse files
committed
调整code
1 parent a946de3 commit 883a90e

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

exception/base.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ type WithAPIException interface {
1818
WithMeta(m interface{}) APIException
1919
}
2020

21-
func newException(namespace Namespace, code int, reason, format string, a ...interface{}) *exception {
21+
func newException(namespace Namespace, code int, format string, a ...interface{}) *exception {
2222
return &exception{
2323
namespace: namespace,
2424
code: code,
25-
reason: reason,
25+
reason: codeReason(code),
2626
message: fmt.Sprintf(format, a...),
2727
}
2828
}

exception/code.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
var (
2222
reasonMap = map[int]string{
2323
Unauthorized: "认证失败",
24-
NotFound: "资源为找到",
24+
NotFound: "资源未找到",
2525
BadRequest: "请求不合法",
2626
InternalServerError: "系统内部错误",
2727
Forbidden: "访问未授权",

exception/exception.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,42 @@ func NewAPIException(namespace string, code int, reason, format string, a ...int
88
code = -1
99
}
1010

11-
return newException(Namespace(namespace), code, reason, format, a...)
11+
return newException(Namespace(namespace), code, format, a...)
1212
}
1313

1414
// NewUnauthorized 未认证
1515
func NewUnauthorized(format string, a ...interface{}) APIException {
16-
return newException(usedNamespace, Unauthorized, codeReason(Unauthorized), format, a...)
16+
return newException(usedNamespace, Unauthorized, format, a...)
1717
}
1818

1919
// NewPermissionDeny 没有权限访问
2020
func NewPermissionDeny(format string, a ...interface{}) APIException {
21-
return newException(usedNamespace, Forbidden, codeReason(Forbidden), format, a...)
21+
return newException(usedNamespace, Forbidden, format, a...)
2222
}
2323

2424
// NewAccessTokenExpired 访问token过期
2525
func NewAccessTokenExpired(format string, a ...interface{}) APIException {
26-
return newException(usedNamespace, AccessTokenExpired, codeReason(AccessTokenExpired), format, a...)
26+
return newException(usedNamespace, AccessTokenExpired, format, a...)
2727
}
2828

2929
// NewRefreshTokenExpired 刷新token过期
3030
func NewRefreshTokenExpired(format string, a ...interface{}) APIException {
31-
return newException(usedNamespace, RefreshTokenExpired, codeReason(RefreshTokenExpired), format, a...)
31+
return newException(usedNamespace, RefreshTokenExpired, format, a...)
3232
}
3333

3434
// NewBadRequest todo
3535
func NewBadRequest(format string, a ...interface{}) APIException {
36-
return newException(usedNamespace, BadRequest, codeReason(BadRequest), format, a...)
36+
return newException(usedNamespace, BadRequest, format, a...)
3737
}
3838

3939
// NewNotFound todo
4040
func NewNotFound(format string, a ...interface{}) APIException {
41-
return newException(usedNamespace, NotFound, codeReason(BadRequest), format, a...)
41+
return newException(usedNamespace, NotFound, format, a...)
4242
}
4343

4444
// NewInternalServerError 500
4545
func NewInternalServerError(format string, a ...interface{}) APIException {
46-
return newException(usedNamespace, InternalServerError, codeReason(InternalServerError), format, a...)
46+
return newException(usedNamespace, InternalServerError, format, a...)
4747
}
4848

4949
// IsNotFoundError 判断是否是NotFoundError

0 commit comments

Comments
 (0)