internal

package
v0.0.0-...-840d798 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BizExtraKeyAffectStability = "biz_err_affect_stability"
	BizExtraKeyCustomExtra     = "biz_err_custom_extra"
)
View Source
const (
	DefaultErrorMsg          = "Service Internal Error"
	DefaultIsAffectStability = true
)

Variables

View Source
var (
	ServiceInternalErrorCode int32 = 1
	CodeDefinitions                = make(map[int32]*CodeDefinition)
)

Functions

func FromStatusError

func FromStatusError(err error) (statusErr *statusError, ok bool)

FromStatusError converts err to StatusError. 解析RPC返回的error, 如果是statusError转换而来, 则返回ok为true

func GetStatusError

func GetStatusError(err error) *statusError

GetStatusError 获取错误链中最顶层的 StatusError. 如果有获取code或其他扩展字段的需求,再考虑对外暴露

func NewByCode

func NewByCode(code int32, options ...Option) *handlerErr

func Register

func Register(code int32, msg string, opts ...RegisterOption)

func SetDefaultErrorCode

func SetDefaultErrorCode(code int32)

func WithStackTraceIfNotExists

func WithStackTraceIfNotExists(err error) error

func WrapByCode

func WrapByCode(err error, code int32, options ...Option) *handlerErr

func Wrapf

func Wrapf(err error, format string, args ...interface{}) error

Types

type CodeDefinition

type CodeDefinition struct {
	Code              int32
	Message           string
	IsAffectStability bool
}

type Extension

type Extension struct {
	IsAffectStability bool              // 稳定性标识 可用于SLA稳定的监测. true:会影响系统稳定性, 并体现在接口错误率中, false:不影响稳定性
	Extra             map[string]string // 扩展信息
}

type KiteXBizStatusError

type KiteXBizStatusError = kerrors.BizStatusErrorIface

KiteXBizStatusError satisfy the interface requirement of Kitex biz exception handling Kitex-biz exception usage doc: https://www.cloudwego.io/zh/docs/kitex/tutorials/basic-feature/bizstatuserr/

type Option

type Option func(ws *withStatus)

func WithExtra

func WithExtra(extra map[string]string) Option

func WithExtraMsg

func WithExtraMsg(extraMsg string) Option

func WithMsgParam

func WithMsgParam(k, v string) Option

type RegisterOption

type RegisterOption func(definition *CodeDefinition)

func WithAffectStability

func WithAffectStability(affectStability bool) RegisterOption

type StackTracer

type StackTracer interface {
	StackTrace() string
}

type StatusError

type StatusError interface {
	error
	Code() int32
}

StatusError is interface for error with statusError. 如果有获取code或其他扩展字段的需求,再考虑对外暴露接口.

Jump to

Keyboard shortcuts

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