Documentation ¶
Index ¶
- Constants
- func IsConflictError(err error) bool
- func IsNotFoundError(err error) bool
- type APIException
- func NewAPIException(namespace string, code int, reason, format string, a ...interface{}) *APIException
- func NewAPIExceptionFromError(err error) *APIException
- func NewAPIExceptionFromString(msg string) *APIException
- func NewAccessTokenExpired(format string, a ...interface{}) *APIException
- func NewAccessTokenIllegal(format string, a ...interface{}) *APIException
- func NewBadRequest(format string, a ...interface{}) *APIException
- func NewConflict(format string, a ...interface{}) *APIException
- func NewInternalServerError(format string, a ...interface{}) *APIException
- func NewNotFound(format string, a ...interface{}) *APIException
- func NewOtherClientsLoggedIn(format string, a ...interface{}) *APIException
- func NewOtherIPLoggedIn(format string, a ...interface{}) *APIException
- func NewOtherPlaceLoggedIn(format string, a ...interface{}) *APIException
- func NewPasswordExired(format string, a ...interface{}) *APIException
- func NewPermissionDeny(format string, a ...interface{}) *APIException
- func NewRefreshTokenExpired(format string, a ...interface{}) *APIException
- func NewRefreshTokenIllegal(format string, a ...interface{}) *APIException
- func NewSessionTerminated(format string, a ...interface{}) *APIException
- func NewUnauthorized(format string, a ...interface{}) *APIException
- func NewVerifyCodeRequiredError(format string, a ...interface{}) *APIException
- func (e *APIException) Error() string
- func (e *APIException) ErrorCode() int
- func (e *APIException) GetData() interface{}
- func (e *APIException) GetHttpCode() int
- func (e *APIException) GetMeta() interface{}
- func (e *APIException) GetNamespace() string
- func (e *APIException) GetReason() string
- func (e *APIException) Is(t error) bool
- func (e *APIException) ToJson() string
- func (e *APIException) WithData(d interface{}) *APIException
- func (e *APIException) WithHttpCode(httpCode int)
- func (e *APIException) WithMeta(m interface{}) *APIException
- func (e *APIException) WithNamespace(ns string)
Constants ¶
View Source
const ( // OtherPlaceLoggedIn 登录登录 OtherPlaceLoggedIn = 50010 // OtherIPLoggedIn 异常IP登录 OtherIPLoggedIn = 50011 // OtherClientsLoggedIn 用户已经通过其他端登录 OtherClientsLoggedIn = 50012 // SessionTerminated 会话中断 SessionTerminated = 50013 // AccessTokenExpired token过期 AccessTokenExpired = 50014 // RefreshTokenExpired token过期 RefreshTokenExpired = 50015 // AccessTokenIllegal 访问token不合法 AccessTokenIllegal = 50016 // RefreshTokenIllegal 刷新token不合法 RefreshTokenIllegal = 50017 // VerifyCodeRequired 需要验证码 VerifyCodeRequired = 50018 // PasswordExired 用户密码过期 PasswordExired = 50019 Unauthorized = http.StatusUnauthorized // BadRequest 请求不合法 BadRequest = http.StatusBadRequest // InternalServerError 服务端内部错误 InternalServerError = http.StatusInternalServerError // Forbidden 无权限 Forbidden = http.StatusForbidden // NotFound 接口未找到 NotFound = http.StatusNotFound // Conflict 资源冲突, 已经存在 Conflict = http.StatusConflict // UnKnownException 未知异常 UnKnownException = 99999 )
View Source
const (
// GRPC Trailer 异常转换时定义的key名称
TRAILER_ERROR_JSON_KEY = "err_json"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type APIException ¶
type APIException struct { Namespace string `json:"namespace"` HttpCode int `json:"http_code"` ErrCode int `json:"error_code"` Reason string `json:"reason"` Message string `json:"message"` Meta any `json:"meta"` Data any `json:"data"` }
APIException API异常
func NewAPIException ¶
func NewAPIException(namespace string, code int, reason, format string, a ...interface{}) *APIException
NewAPIException 创建一个API异常 用于其他模块自定义异常
func NewAPIExceptionFromError ¶
func NewAPIExceptionFromError(err error) *APIException
{"namespace":"","http_code":404,"error_code":404,"reason":"资源未找到","message":"test","meta":null,"data":null}
func NewAPIExceptionFromString ¶
func NewAPIExceptionFromString(msg string) *APIException
func NewAccessTokenExpired ¶
func NewAccessTokenExpired(format string, a ...interface{}) *APIException
NewAccessTokenExpired 访问token过期
func NewAccessTokenIllegal ¶
func NewAccessTokenIllegal(format string, a ...interface{}) *APIException
NewAccessTokenIllegal 访问token过期
func NewBadRequest ¶
func NewBadRequest(format string, a ...interface{}) *APIException
NewBadRequest todo
func NewInternalServerError ¶
func NewInternalServerError(format string, a ...interface{}) *APIException
NewInternalServerError 500
func NewOtherClientsLoggedIn ¶
func NewOtherClientsLoggedIn(format string, a ...interface{}) *APIException
NewOtherClientsLoggedIn 其他端登录
func NewOtherIPLoggedIn ¶
func NewOtherIPLoggedIn(format string, a ...interface{}) *APIException
NewOtherIPLoggedIn 异常IP登录
func NewOtherPlaceLoggedIn ¶
func NewOtherPlaceLoggedIn(format string, a ...interface{}) *APIException
NewOtherPlaceLoggedIn 异地登录
func NewPasswordExired ¶
func NewPasswordExired(format string, a ...interface{}) *APIException
NewPasswordExired 50019
func NewPermissionDeny ¶
func NewPermissionDeny(format string, a ...interface{}) *APIException
NewPermissionDeny 没有权限访问
func NewRefreshTokenExpired ¶
func NewRefreshTokenExpired(format string, a ...interface{}) *APIException
NewRefreshTokenExpired 刷新token过期
func NewRefreshTokenIllegal ¶
func NewRefreshTokenIllegal(format string, a ...interface{}) *APIException
NewRefreshTokenIllegal 访问token过期
func NewSessionTerminated ¶
func NewSessionTerminated(format string, a ...interface{}) *APIException
NewSessionTerminated 会话结束
func NewUnauthorized ¶
func NewUnauthorized(format string, a ...interface{}) *APIException
NewUnauthorized 未认证
func NewVerifyCodeRequiredError ¶
func NewVerifyCodeRequiredError(format string, a ...interface{}) *APIException
NewVerifyCodeRequiredError 50018
func (*APIException) Error ¶
func (e *APIException) Error() string
func (*APIException) ErrorCode ¶
func (e *APIException) ErrorCode() int
Code exception's code, 如果code不存在返回-1
func (*APIException) GetData ¶
func (e *APIException) GetData() interface{}
func (*APIException) GetHttpCode ¶
func (e *APIException) GetHttpCode() int
Code exception's code, 如果code不存在返回-1
func (*APIException) GetMeta ¶
func (e *APIException) GetMeta() interface{}
func (*APIException) GetNamespace ¶
func (e *APIException) GetNamespace() string
func (*APIException) GetReason ¶
func (e *APIException) GetReason() string
func (*APIException) Is ¶
func (e *APIException) Is(t error) bool
func (*APIException) ToJson ¶
func (e *APIException) ToJson() string
func (*APIException) WithData ¶
func (e *APIException) WithData(d interface{}) *APIException
func (*APIException) WithHttpCode ¶
func (e *APIException) WithHttpCode(httpCode int)
func (*APIException) WithMeta ¶
func (e *APIException) WithMeta(m interface{}) *APIException
WithMeta 携带一些额外信息
func (*APIException) WithNamespace ¶
func (e *APIException) WithNamespace(ns string)
Click to show internal directories.
Click to hide internal directories.