fserr

package module
v0.2.16-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: GPL-3.0 Imports: 3 Imported by: 4

README

fserr

方是错误封装

v2alpha版本更新

特性

  1. 采用6位错误码定位具体错误类型,并根据错误类型给出更加具体的错误信息;
  2. 用户无感知的栈信息;
  3. 兼容主流错误风格及api,高度可替换性。

快速开始

package main

import (
	"fmt"
	"git.sxidc.com/service-supports/fserr/v2alpha"
)

const (
	ErrProjectNotExist = iota + 201
)

func init() {
	// 设置服务码
	fserr.SetAppCode(10)

	// fserr包内置错误码
	fserr.NewOK(fserr.ErrDb, "处理失败,请联系开发人员")

	// 业务模块错误
	fserr.NewOK(ErrProjectNotExist, "项目不存在")
}

func Add() error {
	return fserr.WithCode(nil, ErrProjectNotExist)
}

func main() {
	err := Add()
	if err != nil {
		fmt.Printf("%+v\n", fserr.ParseCode(err))
		return
	}
}

Documentation

Index

Constants

View Source
const (
	ErrUnknownCode      uint32 = 0x00000001
	ErrParamCode        uint32 = 0x00000002
	ErrConflictCode     uint32 = 0x00000003
	ErrNotExistCode     uint32 = 0x00000004
	ErrTypeTransferCode uint32 = 0x00000005
	ErrAuthCode         uint32 = 0x00000006
	ErrDataCode         uint32 = 0x00000007
	ErrCustomCode       uint32 = 0x00001000
)

Variables

This section is empty.

Functions

func ExplainCode

func ExplainCode(code uint32) string

Types

type Error

type Error struct {
	StackMessage string
	// contains filtered or unexported fields
}

func NewAuthError

func NewAuthError(message string) *Error

func NewConflictError

func NewConflictError(message string) *Error

func NewCustomError

func NewCustomError(message string) *Error

func NewDataError added in v0.1.7

func NewDataError(message string) *Error

func NewError added in v0.1.8

func NewError(code uint32, message string) *Error

func NewNotExistError

func NewNotExistError(message string) *Error

func NewParamError

func NewParamError(message string) *Error

func NewTypeTransferError

func NewTypeTransferError(message string) *Error

func NewUnknownError

func NewUnknownError(message string) *Error

func TransferFromError

func TransferFromError(err error) *Error

func (*Error) Code

func (err *Error) Code() uint32

func (*Error) Error

func (err *Error) Error() string

func (*Error) Format added in v0.1.5

func (err *Error) Format(s fmt.State, verb rune)

func (*Error) Is

func (err *Error) Is(target error) bool

func (*Error) WithStack

func (err *Error) WithStack() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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