errs

package
v0.0.0-...-dd7b778 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package errs 用于表示以 RPC 为主的错误信息, 同时也可以进行相关错误转换逻辑

Index

Constants

View Source
const (
	// ParameterWrongCode 错误代码: 请求参数错误
	ParameterWrongCode = 10000
	// InternalErrorCode 错误代码: 服务内部异常
	InternalErrorCode = 10001
	// RPCErrorCode 错误代码: RPC 调用错误
	RPCErrorCode = 10002
	// DBErrorCode 错误代码: 数据库操作失败
	DBErrorCode = 10003
	// PasswordErrorCode 错误代码: 密码比对失败
	PasswordErrorCode = 10011
	// UserNotExistCode 错误代码: 用户不存在
	UserNotExistCode = 10012
)

Variables

View Source
var (
	// ParameterWrong 请求参数错误
	ParameterWrong = errs.New(ParameterWrongCode, "请求参数错误")
	// InternalError 服务内部异常
	InternalError = errs.New(InternalErrorCode, "服务内部异常")
	// RPCError RPC 调用错误
	RPCError = errs.New(RPCErrorCode, "RPC 调用错误")
	// DBError 数据库操作失败
	DBError = errs.New(DBErrorCode, "数据库操作失败")
	// PasswordError 密码比对失败
	PasswordError = errs.New(PasswordErrorCode, "密码错误")
	// UserNotExist 用户不存在
	UserNotExist = errs.New(UserNotExistCode, "用户不存在")
)

Functions

func Is

func Is(err, target error) bool

封装官方 errors.Is, 主要是方便调用方不用 import 两个包

func Join

func Join(errs ...error) error

封装官方 errors.Join, 主要是方便调用方不用 import 两个包

func New

func New[T constraints.Integer](code T, message string) error

New 返回带 code 和 message 的错误, 是 trpc 框架 errs.New 的封装

func Raw

func Raw(message string) error

Raw 表示原生 errors.New 的封装

Types

This section is empty.

Jump to

Keyboard shortcuts

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