邹方成 1ab39d2f5a
Some checks failed
Build docker and publish / linux (1.24.5) (push) Failing after 25s
refactor: 重构项目结构并重命名模块
feat(admin): 新增工会管理功能
feat(activity): 添加活动管理相关服务
feat(user): 实现用户道具卡和积分管理
feat(guild): 新增工会成员管理功能

fix: 修复数据库连接配置
fix: 修正jwtoken导入路径
fix: 解决端口冲突问题

style: 统一代码格式和注释风格
style: 更新项目常量命名

docs: 添加项目框架和开发规范文档
docs: 更新接口文档注释

chore: 移除无用代码和文件
chore: 更新Makefile和配置文件
chore: 清理日志文件

test: 添加道具卡测试脚本
2025-11-14 21:10:00 +08:00

83 lines
1.5 KiB
Go

package core
import (
"bindbox-game/internal/pkg/errors"
)
var _ BusinessError = (*businessError)(nil)
type BusinessError interface {
// i 为了避免被其他包实现
i()
// WithError 设置错误信息
WithError(err error) BusinessError
// WithAlert 设置告警通知
WithAlert() BusinessError
// BusinessCode 获取业务码
BusinessCode() int
// HTTPCode 获取 HTTP 状态码
HTTPCode() int
// Message 获取错误描述
Message() string
// StackError 获取带堆栈的错误信息
StackError() error
// IsAlert 是否开启告警通知
IsAlert() bool
}
type businessError struct {
httpCode int // HTTP 状态码
businessCode int // 业务码
message string // 错误描述
stackError error // 含有堆栈信息的错误
isAlert bool // 是否告警通知
}
func Error(httpCode, businessCode int, message string) BusinessError {
return &businessError{
httpCode: httpCode,
businessCode: businessCode,
message: message,
isAlert: false,
}
}
func (e *businessError) i() {}
func (e *businessError) WithError(err error) BusinessError {
e.stackError = errors.WithStack(err)
return e
}
func (e *businessError) WithAlert() BusinessError {
e.isAlert = true
return e
}
func (e *businessError) HTTPCode() int {
return e.httpCode
}
func (e *businessError) BusinessCode() int {
return e.businessCode
}
func (e *businessError) Message() string {
return e.message
}
func (e *businessError) StackError() error {
return e.stackError
}
func (e *businessError) IsAlert() bool {
return e.isAlert
}