Skip to content

Commit 2dd47c1

Browse files
committed
添加刷新token过期异常
1 parent 22cfd33 commit 2dd47c1

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

exception/code.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package exception
33
import "net/http"
44

55
const (
6-
// TokenExpired token过期
7-
TokenExpired = 1000
6+
// AccessTokenExpired token过期
7+
AccessTokenExpired = 1000
8+
// RefreshTokenExpired token过期
9+
RefreshTokenExpired = 1001
810

911
// 1xx - 5xx copy from http status code
1012
Unauthorized = http.StatusUnauthorized
@@ -24,7 +26,8 @@ var (
2426
InternalServerError: "系统内部错误",
2527
Forbidden: "访问未授权",
2628
UnKnownException: "未知异常",
27-
TokenExpired: "访问过期, 请重新访问",
29+
AccessTokenExpired: "访问过期, 请刷新",
30+
RefreshTokenExpired: "刷新过期, 请登录",
2831
}
2932
)
3033

exception/exception.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ func NewPermissionDeny(format string, a ...interface{}) APIException {
2121
return newException(usedNamespace, Forbidden, codeReason(Forbidden), format, a...)
2222
}
2323

24-
// NewTokenExpired token过期
25-
func NewTokenExpired(format string, a ...interface{}) APIException {
26-
return newException(usedNamespace, TokenExpired, codeReason(TokenExpired), format, a...)
24+
// NewAccessTokenExpired 访问token过期
25+
func NewAccessTokenExpired(format string, a ...interface{}) APIException {
26+
return newException(usedNamespace, AccessTokenExpired, codeReason(AccessTokenExpired), format, a...)
27+
}
28+
29+
// NewRefreshTokenExpired 刷新token过期
30+
func NewRefreshTokenExpired(format string, a ...interface{}) APIException {
31+
return newException(usedNamespace, RefreshTokenExpired, codeReason(RefreshTokenExpired), format, a...)
2732
}
2833

2934
// NewBadRequest todo

http/mock/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (m *mockAuther) Auth(h http.Header, entry router.Entry) (authInfo interface
3535
access := headerSlice[1]
3636

3737
if access != MockTestToken {
38-
return nil, exception.NewPermissionDeny("permission deny")
38+
return nil, exception.NewUnauthorized("permission deny")
3939
}
4040
return access, nil
4141
}

0 commit comments

Comments
 (0)