Help us shape the future of Go! Take the 2026 Go Developer Survey

errors

package
v0.32.41 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

shareblocked.go 分享管控拒绝态错误(治理状态机的 typed error 词汇表)。

历史:app/share.ShareBlockedError 与 app/anonymous.BlockedError 曾各持一份 逐字相同的实现(消息文案与 errcode 映射同款,状态常量还一个用 model 常量 一个用字面量,已有漂移),2026-10-10 合并至此;两域以类型别名消费, handler 侧 errors.As / resp.NewTypedError 用法不变。

Index

Constants

View Source
const (
	CodeSuccess      = errcode.CodeSuccess
	CodeBadRequest   = errcode.CodeInvalidParam
	CodeUnauthorized = errcode.CodeUnauthorized
	CodeForbidden    = errcode.CodeForbidden
	CodeNotFound     = errcode.CodeNotFound
	// CodeConflict:contracts v0.15.1 起直接引用 errcode 常量(v0.22.0 tag 时该常量
	// 未发布曾本地同值,随 deps 仪式切回引用,值不变)。
	CodeConflict           = errcode.CodeConflict
	CodeInternalError      = errcode.CodeInternal
	CodeServiceUnavailable = errcode.CodeUnavailable
	CodeTooManyRequests    = errcode.CodeRateLimit
)

统一错误码(2026-10-15):legacy 1001-1008 退役,常量名保留为 errcode 别名重钉到 contracts/errcode 对应值——全部经由常量的发射点一次性迁移, 无需改任何调用方。wire 上旧值不再出现(破坏性变更,随主/次版本公告, 对照表见文档站 error-codes 页):

1001 → 10001 InvalidParam
1002 → 10002 Unauthorized
1003 → 10003 Forbidden
1004 → 10004 NotFound
1005 → 10016 Conflict(errcode 新增)
1006 → 10008 Internal
1007 → 10006 Unavailable
1008 → 10005 RateLimit
View Source
const (
	ShareStatusBlocked       = "blocked"
	ShareStatusPendingReview = "pending_review"
)

分享治理状态字面量。pkg 层不得 import repo(架构守卫规则 1),故此处独立 定义并与 repo/db/model 的同名常量对齐——app 层测试钉死防漂移断言。

Variables

This section is empty.

Functions

func GetErrorCode

func GetErrorCode(err error) int

GetErrorCode 取错误的业务码;非 AppError 一律回退 CodeInternalError。

口径与迁移前逐字一致:仅识别**直接**的 *AppError,故刻意不用上游 AsBizError。

func GetMessage

func GetMessage(code int) string

func IsAppError

func IsAppError(err error) bool

IsAppError 判断错误是否为 AppError。

口径与迁移前逐字一致:仅匹配**直接**的 *AppError(不做 errors.As 链式匹配), 故刻意不用上游 IsBizError(后者走 errors.As,命中面更宽)。

Types

type AppError

type AppError = oekiterrors.BizError

AppError 是上游 oekit/pkg/errors.BizError 的别名——自研的 AppError{Code,Message,Cause} 与上游 BizError{BizCode,HTTPCode,Message,Cause} 语义同构(业务码 + 描述 + 可选 cause),收编后仓内只留一份实现。

差异(上游形态为准):

  • 字段名 Code → BizCode(上游命名),并新增 HTTPCode(HTTP 状态码,0=由 调用方映射;本包构造器不设置,与迁移前一致);
  • Error() 文案多出 "biz_code:%d " 前缀(原为纯 message)。

本仓无任何调用点(AppError 及其构造器全仓仅本文件自身引用,qnap/server/ openwrt/fnos 四个消费仓均未引用 pkg/errors),故上述差异无对外可观测影响。

func BadRequest

func BadRequest(message string) *AppError

func Conflict

func Conflict(message string) *AppError

func Forbidden

func Forbidden(message string) *AppError

func InternalError

func InternalError(message string) *AppError

func New

func New(code int, message string) *AppError

New 构造一个业务错误(业务码 + 描述)。

func NotFound

func NotFound(message string) *AppError

func Unauthorized

func Unauthorized(message string) *AppError

func Wrap

func Wrap(code int, message string, cause error) *AppError

Wrap 构造一个带原始错误的业务错误。

type ShareBlocked added in v0.15.1

type ShareBlocked struct {
	Status string
}

ShareBlocked 分享处于管控拒绝态(管理员禁用 / 待审核)。 handler 侧按 ErrCode 透传(20012 blocked / 20013 pending_review)。

func (*ShareBlocked) ErrCode added in v0.15.1

func (e *ShareBlocked) ErrCode() int

func (*ShareBlocked) Error added in v0.15.1

func (e *ShareBlocked) Error() string

Jump to

Keyboard shortcuts

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