exception

package
v0.0.0-...-28af436 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2023 License: MIT Imports: 2 Imported by: 0

README

自定义业务异常

record not found, xxxxxx

光一个字符串 满足不了业务异常的定义需求, 也不具体可扩展性

常见的作法是 自定义结果化的异常消息

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNotFound

func IsNotFound(err error) bool

Types

type ApiException

type ApiException struct {
	// 业务异常
	BizCode  int    `json:"code"`
	Message  string `json:"message"`
	Data     any    `json:"data"`
	HttpCode int    `json:"http_code"`
}

业务自定义异常

func New

func New(code int, format string, a ...any) *ApiException

New(5000, "令牌过期...")

func NewAuthFailed

func NewAuthFailed(format string, a ...any) *ApiException

func NewNotFound

func NewNotFound(format string, a ...any) *ApiException

func NewPermissionDeny

func NewPermissionDeny(format string, a ...any) *ApiException

func NewTokenExpired

func NewTokenExpired(format string, a ...any) *ApiException

func (*ApiException) Error

func (e *ApiException) Error() string

实现Error接口

Jump to

Keyboard shortcuts

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