exception

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package exception 提供异常处理和错误响应功能,支持业务异常和验证异常两种类型。 支持从全局管理器中获取预定义异常,也支持自定义异常创建和抛出。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Throw

func Throw(key string, d ...interface{})

Throw 方法用于抛出业务异常(直接 panic)。

func VeThrow

func VeThrow(key string, d ...interface{})

VeThrow 方法用于抛出验证异常(直接 panic)。

Types

type ErrorData

type ErrorData map[string]string

type Exception

type Exception response.RespInfo

func Get

func Get(key string) *Exception

Get 方法用于获取业务异常(直接 panic 后可被 recover 捕获)。

func GetIllegalRequest

func GetIllegalRequest() *Exception

GetIllegalRequest 常见异常错误方法

func GetInputError

func GetInputError() *Exception

GetInputError 常见异常错误方法

func GetInternalError

func GetInternalError() *Exception

func GetNotFoundDocument

func GetNotFoundDocument() *Exception

GetNotFoundDocument 常见异常错误方法

func GetUnknownError

func GetUnknownError() *Exception

func New

func New(c int, m string, d ...interface{}) *Exception

func (*Exception) Error

func (e *Exception) Error() string

Exception Error 实现 error 接口

func (*Exception) ErrorCustom

func (e *Exception) ErrorCustom(code int, msg string) response.IResponse

ErrorCustom 错误时的响应,重置code和msg字段

func (*Exception) From

func (e *Exception) From(r response.IResponse, needToRelease bool) response.IResponse

From 从另一个 IResponse 复制数据

func (*Exception) GetCode

func (e *Exception) GetCode() int

GetCode 获取响应代码

func (*Exception) GetData

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

GetData 获取响应数据

func (*Exception) GetMsg

func (e *Exception) GetMsg() string

GetMsg 获取响应消息

func (*Exception) JsonWithCtx

func (e *Exception) JsonWithCtx(c providerctx.ICoreContext, status ...int) error

JsonWithCtx Exception 使用 ContextProvider 上下文响应 JSON

func (*Exception) Panic

func (e *Exception) Panic()

Panic Exception 直接panic

func (*Exception) Release

func (e *Exception) Release()

func (*Exception) Reset

func (e *Exception) Reset(code int, msg string, data interface{}) response.IResponse

Reset 重置 Exception 字段

func (*Exception) RespData

func (e *Exception) RespData(d ...interface{}) *Exception

RespData 方法用于响应错误,并可添加数据参数

func (*Exception) SendWithCtx

func (e *Exception) SendWithCtx(c providerctx.ICoreContext, status ...int) error

SendWithCtx 使用 ICoreContext 上下文提供者返回 JSON 响应

func (*Exception) SuccessWithData

func (e *Exception) SuccessWithData(data ...interface{}) response.IResponse

SuccessWithData 成功时的响应,重置data字段

type ExceptionMap

type ExceptionMap map[string]Exception

type ValidateException

type ValidateException response.RespInfo

func NewVE

func NewVE(c int, m string, d ...interface{}) *ValidateException

func VeGet

func VeGet(key string) *ValidateException

VeGet 方法用于获取验证异常(直接 panic 后可被 recover 捕获)。

func VeGetInputError

func VeGetInputError() *ValidateException

VeGetInputError 常见验证类错误方法

func VeGetInternalError

func VeGetInternalError() *ValidateException

func VeGetNotFoundError

func VeGetNotFoundError() *ValidateException

func VeGetUnknownError

func VeGetUnknownError() *ValidateException

func (*ValidateException) Error

func (e *ValidateException) Error() string

ValidateException Error 实现 error 接口

func (*ValidateException) ErrorCustom

func (e *ValidateException) ErrorCustom(code int, msg string) response.IResponse

ErrorCustom 错误时的响应,重置code和msg字段

func (*ValidateException) From

func (e *ValidateException) From(r response.IResponse, needToRelease bool) response.IResponse

From 从另一个 IResponse 复制数据

func (*ValidateException) GetCode

func (e *ValidateException) GetCode() int

GetCode 获取响应代码

func (*ValidateException) GetData

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

GetData 获取响应数据

func (*ValidateException) GetMsg

func (e *ValidateException) GetMsg() string

GetMsg 获取响应消息

func (*ValidateException) JsonWithCtx

func (e *ValidateException) JsonWithCtx(c providerctx.ICoreContext, status ...int) error

JsonWithCtx ValidateException 使用 ContextProvider 上下文响应 JSON

func (*ValidateException) Panic

func (e *ValidateException) Panic()

Panic ValidateException 直接panic

func (*ValidateException) Release

func (e *ValidateException) Release()

Release 释放 ValidateException 内部RespInfo对象回对象池

func (*ValidateException) Reset

func (e *ValidateException) Reset(code int, msg string, data interface{}) response.IResponse

Reset 重置 ValidateException 字段

func (*ValidateException) RespData

func (e *ValidateException) RespData(d ...interface{}) *ValidateException

RespData 方法用于响应错误,并可添加数据参数

func (*ValidateException) SendWithCtx

func (e *ValidateException) SendWithCtx(c providerctx.ICoreContext, status ...int) error

SendWithCtx 使用 ICoreContext 上下文提供者返回 JSON 响应

func (*ValidateException) SuccessWithData

func (e *ValidateException) SuccessWithData(data ...interface{}) response.IResponse

SuccessWithData 成功时的响应,重置data字段

Jump to

Keyboard shortcuts

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