errors

package module
v0.0.0-...-6d4b899 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 1 Imported by: 1

Documentation

Overview

Package errors Date: 2023/11/23 14:55 Author: Amu Description:

Index

Constants

View Source
const (
	InternalServeError    = "internal server error"
	InvalidToken          = "invalid token"
	InvalidUserOrPassword = "invalid username or password"
	MethodNotAllow        = "method not allowed"
	NotFound              = "not found"
	TooManyRequests       = "too many requests"
	Forbidden             = "forbidden"
	BadRequest            = "bad request"
)

Variables

View Source
var (
	Is           = errors.Is
	New          = errors.New
	Wrap         = errors.Wrap
	Wrapf        = errors.Wrapf
	WithStack    = errors.WithStack
	WithMessage  = errors.WithMessage
	WithMessagef = errors.WithMessagef
)

Define alias

View Source
var (
	ErrInvalidToken    = NewError(401, InvalidToken)
	ErrForbidden       = NewError(403, Forbidden)
	ErrNotFound        = NewError(404, NotFound)
	ErrMethodNotAllow  = NewError(405, MethodNotAllow)
	ErrTooManyRequests = NewError(429, TooManyRequests)
	ErrInternalServer  = New500Error(InternalServeError)
	ErrBadRequest      = New400Error(BadRequest)
	ErrInvalidAccount  = New400Error(InvalidUserOrPassword)
)

Functions

func New400Error

func New400Error(msg string) error

func New500Error

func New500Error(msg string) error

func WrapError

func WrapError(err error, status int, msg string) error

Types

type Error

type Error struct {
	Message string // 错误消息
	Status  int    // 响应状态码
	ERR     error  // 响应错误
}

Error 定义响应错误

func NewError

func NewError(status int, msg string) *Error

func UnWrapError

func UnWrapError(err error) *Error

func (*Error) CodeStatus

func (r *Error) CodeStatus() int

func (*Error) Error

func (r *Error) Error() string

Jump to

Keyboard shortcuts

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