goerror

package
v1.2.65 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

有状态信息的错误封装

package main

import (
	goerror "github.com/gif-gif/go.io/go-error"
	golog "github.com/gif-gif/go.io/go-log"
	"github.com/pkg/errors"
)

func main() {
	err := errors.Wrapf(goerror.NewErrCode(goerror.DB_ERROR), "find customer db err, in:%v , err:%v", "args", "err")
	if goerror.IsCodeErr(goerror.DB_ERROR) {
		golog.WithTag("goerror1").Error(err.Error(), " db error")
	}

	if goerror.IsErrCode(err, goerror.DB_ERROR) {
		golog.WithTag("goerror2").Error(err.Error(), " db error")
	}
	errCode, errMsg := goerror.GetErrCodeMsg(err)
	golog.WithTag("goerror3").Error(errCode, errMsg)
}

Documentation

Index

Constants

View Source
const CAPTCHA_ERROR uint32 = 700
View Source
const DB_ERROR uint32 = 555
View Source
const DB_UPDATE_AFFECTED_ZERO_ERROR uint32 = 556
View Source
const FORBIDDEN_ERROR uint32 = 403
View Source
const NOT_FOUND_ERROR uint32 = 404
View Source
const OK uint32 = 0

成功返回

View Source
const REQUEST_PARAM_ERROR uint32 = 400

全局错误码 client

View Source
const SERVER_COMMON_ERROR uint32 = 500

server

View Source
const TOKEN_EXPIRE_ERROR uint32 = 401
View Source
const TOKEN_GENERATE_ERROR uint32 = 560

Variables

View Source
var (
	ErrNotFound          = NewErrCodeMsg(NOT_FOUND_ERROR, "not found")
	ErrUserNoExists      = NewErrCodeMsg(TOKEN_EXPIRE_ERROR, "user not found")
	ErrUserForbidden     = NewErrCode(FORBIDDEN_ERROR)
	ErrUnauthorized      = NewErrCodeMsg(TOKEN_EXPIRE_ERROR, "unauthorized")
	ErrCaptcha           = NewErrCodeMsg(CAPTCHA_ERROR, "captcha error")
	ErrRequestParamError = NewErrCode(REQUEST_PARAM_ERROR)
	ErrDBError           = NewErrCode(DB_ERROR)
	ErrServerError       = NewErrCode(SERVER_COMMON_ERROR)
)

Functions

func GetErrCodeMsg

func GetErrCodeMsg(err error) (errCode uint32, errMsg string)

func IsCodeErr

func IsCodeErr(errcode uint32) bool

func IsErrCode

func IsErrCode(err error, code uint32) bool

func MapErrMsg

func MapErrMsg(errcode uint32) string

Types

type CodeError

type CodeError struct {
	// contains filtered or unexported fields
}

func NewErrCode

func NewErrCode(errCode uint32) *CodeError

func NewErrCodeMsg

func NewErrCodeMsg(errCode uint32, errMsg string) *CodeError

func NewErrMsg

func NewErrMsg(errMsg string) *CodeError

func NewParamErrMsg

func NewParamErrMsg(errMsg string) *CodeError

func (*CodeError) Error

func (e *CodeError) Error() string

func (*CodeError) GetErrCode

func (e *CodeError) GetErrCode() uint32

返回给前端的错误码

func (*CodeError) GetErrMsg

func (e *CodeError) GetErrMsg() string

返回给前端显示端错误信息

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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