exception

package
v2.0.47 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2024 License: MIT Imports: 5 Imported by: 74

Documentation

Index

Constants

View Source
const (
	// CODE_OTHER_PLACE_LGOIN 登录登录
	CODE_OTHER_PLACE_LGOIN = 50010
	// CODE_OTHER_IP_LOGIN 异常IP登录
	CODE_OTHER_IP_LOGIN = 50011
	// CODE_OTHER_CLIENT_LOGIN 用户已经通过其他端登录
	CODE_OTHER_CLIENT_LOGIN = 50012
	// CODE_SESSION_TERMINATED 会话中断
	CODE_SESSION_TERMINATED = 50013
	// CODE_ACESS_TOKEN_EXPIRED token过期
	CODE_ACESS_TOKEN_EXPIRED = 50014
	// CODE_REFRESH_TOKEN_EXPIRED token过期
	CODE_REFRESH_TOKEN_EXPIRED = 50015
	// CODE_ACCESS_TOKEN_ILLEGAL 访问token不合法
	CODE_ACCESS_TOKEN_ILLEGAL = 50016
	// CODE_REFRESH_TOKEN_ILLEGAL 刷新token不合法
	CODE_REFRESH_TOKEN_ILLEGAL = 50017
	// CODE_VERIFY_CODE_REQUIRED 需要验证码
	CODE_VERIFY_CODE_REQUIRED = 50018
	// CODE_PASSWORD_EXPIRED 用户密码过期
	CODE_PASSWORD_EXPIRED = 50019

	// CODE_UNAUTHORIZED 未认证
	CODE_UNAUTHORIZED = http.StatusUnauthorized
	// CODE_BAD_REQUEST 请求不合法
	CODE_BAD_REQUEST = http.StatusBadRequest
	// CODE_INTERNAL_SERVER_ERROR 服务端内部错误
	CODE_INTERNAL_SERVER_ERROR = http.StatusInternalServerError
	// CODE_FORBIDDEN 无权限
	CODE_FORBIDDEN = http.StatusForbidden
	// CODE_NOT_FOUND 接口未找到
	CODE_NOT_FOUND = http.StatusNotFound
	// CODE_CONFLICT 资源冲突, 已经存在
	CODE_CONFLICT = http.StatusConflict

	// CODE_UNKNOWN 未知异常
	CODE_UNKNOWN = 99999
)
View Source
const (
	// GRPC Trailer 异常转换时定义的key名称
	TRAILER_ERROR_JSON_KEY = "err_json"
)

Variables

This section is empty.

Functions

func IsApiException added in v2.0.27

func IsApiException(err error, code int) bool

func IsConflictError

func IsConflictError(err error) bool

IsConflictError 判断是否是Conflict

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError 判断是否是NotFoundError

Types

type ApiException added in v2.0.27

type ApiException struct {
	Service  string         `json:"service"`
	HttpCode int            `json:"http_code,omitempty"`
	Code     int            `json:"code"`
	Reason   string         `json:"reason"`
	Message  string         `json:"message"`
	Meta     map[string]any `json:"meta"`
	Data     any            `json:"data"`
}

ApiException API异常

func NewAPIExceptionFromError

func NewAPIExceptionFromError(err error) *ApiException

{"namespace":"","http_code":404,"error_code":404,"reason":"资源未找到","message":"test","meta":null,"data":null}

func NewAccessTokenExpired

func NewAccessTokenExpired(format string, a ...interface{}) *ApiException

NewAccessTokenExpired 访问token过期

func NewAccessTokenIllegal

func NewAccessTokenIllegal(format string, a ...interface{}) *ApiException

NewAccessTokenIllegal 访问token过期

func NewApiException added in v2.0.27

func NewApiException(code int, reason string) *ApiException

NewApiException 创建一个API异常 用于其他模块自定义异常

func NewApiExceptionFromString added in v2.0.27

func NewApiExceptionFromString(msg string) *ApiException

func NewBadRequest

func NewBadRequest(format string, a ...interface{}) *ApiException

NewBadRequest todo

func NewConflict

func NewConflict(format string, a ...interface{}) *ApiException

NewConflict todo

func NewInternalServerError

func NewInternalServerError(format string, a ...interface{}) *ApiException

NewInternalServerError 500

func NewNotFound

func NewNotFound(format string, a ...interface{}) *ApiException

NewNotFound todo

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 added in v2.0.27

func (e *ApiException) Error() string

func (*ApiException) ErrorCode added in v2.0.27

func (e *ApiException) ErrorCode() int

Code exception's code, 如果code不存在返回-1

func (*ApiException) GetData added in v2.0.27

func (e *ApiException) GetData() interface{}

func (*ApiException) GetHttpCode added in v2.0.27

func (e *ApiException) GetHttpCode() int

Code exception's code, 如果code不存在返回-1

func (*ApiException) GetMeta added in v2.0.27

func (e *ApiException) GetMeta(key string) any

func (*ApiException) GetNamespace added in v2.0.27

func (e *ApiException) GetNamespace() string

func (*ApiException) GetReason added in v2.0.27

func (e *ApiException) GetReason() string

func (*ApiException) Is added in v2.0.27

func (e *ApiException) Is(t error) bool

func (*ApiException) ToJson added in v2.0.27

func (e *ApiException) ToJson() string

func (*ApiException) WithData added in v2.0.27

func (e *ApiException) WithData(d any) *ApiException

func (*ApiException) WithHttpCode added in v2.0.27

func (e *ApiException) WithHttpCode(httpCode int) *ApiException

func (*ApiException) WithMessage added in v2.0.27

func (e *ApiException) WithMessage(m string) *ApiException

func (*ApiException) WithMessagef added in v2.0.27

func (e *ApiException) WithMessagef(format string, a ...any) *ApiException

func (*ApiException) WithMeta added in v2.0.27

func (e *ApiException) WithMeta(key string, value any) *ApiException

WithMeta 携带一些额外信息

func (*ApiException) WithNamespace added in v2.0.27

func (e *ApiException) WithNamespace(ns string) *ApiException

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL