Documentation
¶
Index ¶
- Constants
- Variables
- func Cause(err error) error
- func ErrorHandler(err error) (int, any)
- func ErrorHandlerCtx(ctx context.Context, err error) (int, any)
- func FramesWrapped(err error) bool
- func GrpcCodeFromHttpStatus(status int) codes.Code
- func IsInternal(err error) bool
- func ResultHandler(ctx context.Context, data any) any
- func ShouldLogError(err error) bool
- func StripFrames(err error) error
- func UnwrapFrames(err error) stacktrace.Frames
- func UnwrapMsg(err error) (string, error)
- type Causer
- type ErrProxy
- type Error
- func (e *Error) AsResult() *Result
- func (e *Error) Equal(other *Error) bool
- func (e *Error) ErrCode(ecode int) *Error
- func (e *Error) Error() string
- func (e *Error) ExtMsg(extmsg string) *Error
- func (e *Error) Is(err error) bool
- func (e *Error) Json() string
- func (e *Error) Msg(msg string) *Error
- func (e *Error) Msgf(format string, args ...any) *Error
- func (e *Error) ShouldLogError() bool
- type Result
- type Unwrapper
Constants ¶
View Source
const ( BizNote = 20000 BizPassport = 30000 BizComment = 40000 BizCounter = 50000 BizMsger = 60000 BizRelation = 70000 BizWsLink = 80000 BizConductor = 90000 )
View Source
const ( CodeOk = 0 CodeInvalidParam = 10002 CodeForbidden = 10003 CodeNotFound = 10004 CodeInternal = 10005 CodeCsrfFailed = 10006 CodeDuplicate = 10008 CodeTooLong = 10009 CodeServerSigningFail = 10010 CodeResourceNotFound = 10011 CodeInternalPanic = 19000 CodeOther = 19999 )
业务错误码定义
View Source
const ( Continue = 100 SwitchingProtocols = 101 Processing = 102 EarlyHints = 103 OK = 200 Created = 201 Accepted = 202 NonAuthoritativeInfo = 203 NoContent = 204 ResetContent = 205 PartialContent = 206 MultiStatus = 207 AlreadyReported = 208 IMUsed = 226 MultipleChoices = 300 MovedPermanently = 301 Found = 302 SeeOther = 303 NotModified = 304 UseProxy = 305 TemporaryRedirect = 307 PermanentRedirect = 308 BadRequest = 400 PaymentRequired = 402 Forbidden = 403 NotFound = 404 MethodNotAllowed = 405 NotAcceptable = 406 ProxyAuthRequired = 407 RequestTimeout = 408 Conflict = 409 Gone = 410 LengthRequired = 411 PreconditionFailed = 412 RequestEntityTooLarge = 413 RequestURITooLong = 414 UnsupportedMediaType = 415 RequestedRangeNotSatisfiable = 416 ExpectationFailed = 417 Teapot = 418 MisdirectedRequest = 421 UnprocessableEntity = 422 Locked = 423 FailedDependency = 424 TooEarly = 425 UpgradeRequired = 426 PreconditionRequired = 428 TooManyRequests = 429 RequestHeaderFieldsTooLarge = 431 InternalServerError = 500 NotImplemented = 501 BadGateway = 502 GatewayTimeout = 504 HTTPVersionNotSupported = 505 VariantAlsoNegotiates = 506 InsufficientStorage = 507 LoopDetected = 508 NotExtended = 510 NetworkAuthenticationRequired = 511 )
Variables ¶
View Source
var ( Success = NewError(http.StatusOK, CodeOk, "成功") ErrInvalidArgs = NewError(BadRequest, CodeInvalidParam, "参数出错了(;一_一)") ErrArgs = ErrInvalidArgs ErrNilArg = ErrArgs.Msg("参数为空") ErrNotLogin = NewError(Unauthorized, CodeUnauthorized, "请先登录一下吧~(≧▽≦)") ErrPermission = NewError(Forbidden, CodeForbidden, "需要特殊通行证") ErrNotFound = NewError(NotFound, CodeNotFound, "找不到你要的资源") ErrInternal = NewError(InternalServerError, CodeInternal, "服务器被怪兽踢烂了(ノ`Д´)ノ") ErrDepNotReady = NewError(InternalServerError, CodeInternal, "服务未就绪") ErrInternalPanic = NewError(InternalServerError, CodeInternalPanic, "服务器炸掉了") ErrDuplicate = NewError(InternalServerError, CodeDuplicate, "资源重复") ErrDataTooLong = NewError(InternalServerError, CodeTooLong, "数据超长") ErrServerSigning = NewError(InternalServerError, CodeServerSigningFail, "服务器签名失败") ErrResourceNotFound = NewError(NotFound, CodeResourceNotFound, "资源不存在") ErrCsrf = NewError(Forbidden, CodeCsrfFailed, "CSRF校验失败") ErrOther = NewError(InternalServerError, CodeOther, "服务错误") )
常用错误
View Source
var ( ErrApiWentOffline = NewError(NotFound, CodeOther, "接口不存在(´・ω・`)") ErrPanic = NewError(InternalServerError, -99999, "FATAL PANIC") )
internal user
Functions ¶
func ErrorHandler ¶
func FramesWrapped ¶
func IsInternal ¶
Types ¶
type ErrProxy ¶
type ErrProxy interface {
error
Stack() []*runtime.Frame
Context() context.Context
Fields() map[string]any
Extra() map[string]any
WithCtx(ctx context.Context) ErrProxy
WithField(key string, val any) ErrProxy
WithExtra(key string, val any) ErrProxy
WithFields(kvs ...any) ErrProxy
WithExtras(kvs ...any) ErrProxy
}
type Error ¶
type Error struct {
StatusCode int `json:"stcode,omitempty"` // http响应状态码
Code int `json:"code"` // 业务响应码
Message string `json:"msg"`
}
func (*Error) ShouldLogError ¶
Click to show internal directories.
Click to hide internal directories.