exception

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: MIT Imports: 3 Imported by: 6

Documentation

Index

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
	// cookis is not found for web  浏览器未发现cookis
	WebCookisNotFound = 50020
	//api is not found for web
	ApiUrlNotFound = 50040

	// BadRequest 请求不合法
	BadRequest = http.StatusBadRequest
	// Unauthorized 未认证
	Unauthorized = http.StatusUnauthorized
	// Forbidden 无权限
	Forbidden = http.StatusForbidden
	// NotFound 接口未找到
	NotFound = http.StatusNotFound
	// Conflict 资源冲突, 已经存在
	Conflict = http.StatusConflict
	// InternalServerError 服务端内部错误
	InternalServerError = http.StatusInternalServerError

	// UnKnownException 未知异常
	UnKnownException = 99999
)

Variables

This section is empty.

Functions

This section is empty.

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 NewAPIException1

func NewAPIException1(code int, reason, format string, a ...interface{}) *APIException

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

func NewAccessTokenExpired added in v1.3.1

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

AccessTokenExpired 50014 token过期

func NewAccessTokenIllegal added in v1.3.1

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

RefreshTokenExpired 50016 访问token不合法

func NewApiUrlNotFound added in v1.3.1

func NewApiUrlNotFound(format string, a ...interface{}) *APIException

ApiUrlNotFound 50040 api is not found for web

func NewBadRequest

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

-----------------------------400 code start --------------------------------------// NewBadRequest 400 a 的作用 "Resource not found: %s", "exampleID"

func NewConflict added in v1.3.1

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

Conflict 409 资源冲突, 已经存在

func NewForbidden added in v1.3.1

func NewForbidden(format string, a ...interface{}) *APIException

Forbidden 403

func NewInternalServerError added in v1.2.9

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

NewInternalServerError 500

func NewNotFound

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

NewNotFound 404 a 的作用 "Resource not found: %s", "exampleID"

func NewOtherClientsLoggedIn added in v1.3.1

func NewOtherClientsLoggedIn(format string, a ...interface{}) *APIException

OtherClientsLoggedIn 50012 用户已经通过其他端登录

func NewOtherIPLoggedIn added in v1.3.1

func NewOtherIPLoggedIn(format string, a ...interface{}) *APIException

OtherIPLoggedIn 50011 异常IP登录

func NewOtherPlaceLoggedIn added in v1.3.1

func NewOtherPlaceLoggedIn(format string, a ...interface{}) *APIException

-----------------------------50000-9999 code start --------------------------------------// OtherPlaceLoggedIn 50010 异地登录

func NewPasswordExired added in v1.3.1

func NewPasswordExired(format string, a ...interface{}) *APIException

VerifyCodeRequired 50019 用户密码过期

func NewRefreshTokenExpired added in v1.3.0

func NewRefreshTokenExpired(format string, a ...interface{}) *APIException

RefreshTokenExpired 50015 token过期

func NewRefreshTokenIllegal added in v1.3.1

func NewRefreshTokenIllegal(format string, a ...interface{}) *APIException

RefreshTokenIllegal 50017 刷新token不合法

func NewSessionTerminated added in v1.3.1

func NewSessionTerminated(format string, a ...interface{}) *APIException

SessionTerminated 50013 会话中断

func NewUnKnownException added in v1.3.1

func NewUnKnownException(format string, a ...interface{}) *APIException

UnKnownException 99999 未知异常

func NewUnauthorized added in v1.3.0

func NewUnauthorized(format string, a ...interface{}) *APIException

Unauthorized 401

func NewVerifyCodeRequired added in v1.3.1

func NewVerifyCodeRequired(format string, a ...interface{}) *APIException

VerifyCodeRequired 50018 需要验证码

func NewWebCookisNotFound added in v1.3.1

func NewWebCookisNotFound(format string, a ...interface{}) *APIException

NewWebCookisNotFoundnRequest 50020 cookis is not found for web 浏览器未发现cookis a 的作用 "Resource not found: %s", "exampleID"

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) ToJson

func (e *APIException) ToJson() string

调用这个方法返回结构体的信息

func (*APIException) WithNamespace

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