11package exception
22
3+ import "fmt"
4+
35// NewAPIException 创建一个API异常
46// 用于其他模块自定义异常
57func NewAPIException (namespace string , code int , reason , format string , a ... interface {}) WithAPIException {
@@ -8,7 +10,12 @@ func NewAPIException(namespace string, code int, reason, format string, a ...int
810 code = - 1
911 }
1012
11- return newException (Namespace (namespace ), code , format , a ... )
13+ return & exception {
14+ namespace : Namespace (namespace ),
15+ code : code ,
16+ reason : codeReason (code ),
17+ message : fmt .Sprintf (format , a ... ),
18+ }
1219}
1320
1421// NewUnauthorized 未认证
@@ -21,6 +28,21 @@ func NewPermissionDeny(format string, a ...interface{}) APIException {
2128 return newException (usedNamespace , Forbidden , format , a ... )
2229}
2330
31+ // NewAccessTokenIllegal 访问token过期
32+ func NewAccessTokenIllegal (format string , a ... interface {}) APIException {
33+ return newException (usedNamespace , AccessTokenIllegal , format , a ... )
34+ }
35+
36+ // NewRefreshTokenIllegal 访问token过期
37+ func NewRefreshTokenIllegal (format string , a ... interface {}) APIException {
38+ return newException (usedNamespace , RefreshTokenIllegal , format , a ... )
39+ }
40+
41+ // NewOtherClientsLoggedIn 访问token过期
42+ func NewOtherClientsLoggedIn (format string , a ... interface {}) APIException {
43+ return newException (usedNamespace , OtherClientsLoggedIn , format , a ... )
44+ }
45+
2446// NewAccessTokenExpired 访问token过期
2547func NewAccessTokenExpired (format string , a ... interface {}) APIException {
2648 return newException (usedNamespace , AccessTokenExpired , format , a ... )
0 commit comments