errors

package
v0.0.0-...-f13fc7a Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccessDenied                        = "AccessDenied"
	AlreadyExists                       = "AlreadyExists"
	AuthFailure                         = "AuthFailure"
	BadConfig                           = "BadConfig"
	Blocked                             = "Blocked"
	ConstraintViolation                 = "ConstraintViolation"
	CorruptedData                       = "CorruptedData"
	Gone                                = "Gone"
	InUse                               = "InUse"
	InvalidEnum                         = "InvalidEnum"
	InvalidParameter                    = "InvalidParameter"
	KeyConflict                         = "KeyConflict"
	LimitExceeded                       = "LimitExceeded"
	MissingParameter                    = "MissingParameter"
	NotFound                            = "NotFound"
	SourceDeleted                       = "SourceDeleted"
	OK                                  = "OK"
	Deleted                             = "Deleted"
	PermissionDenied                    = "PermissionDenied"
	RedisError                          = "RedisError"
	ServerError                         = "ServerError"
	SQLError                            = "SQLError"
	Timeout                             = "Timeout"
	TypeMismatch                        = "TypeMismatch"
	StatusError                         = "StatusError"
	UnexpectedArguments                 = "UnexpectedArguments"
	UnknownError                        = "UnknownError"
	VerificationFailure                 = "VerificationFailure"
	InvalidFileExt                      = "InvalidFileExt"
	CallPluginFailure                   = "CallPluginFailure"
	PluginAlreadyRunning                = "PluginAlreadyRunning"
	PluginAlreadyStop                   = "PluginAlreadyStop"
	GetPluginMessageFailure             = "GetPluginMessageFailure"
	PluginInstanceInstallationFailure   = "PluginInstanceInstallationFailure"
	PluginInstanceUninstallationFailure = "PluginInstanceUninstallationFailure"
	PluginInstanceUploadFailure         = "PluginInstanceUploadFailure"
	PluginInstanceEnableFailure         = "PluginInstanceEnableFailure"
	PluginInstanceDisableFailure        = "PluginInstanceDisableFailure"
	PluginInstanceUpgradeFailure        = "PluginInstanceUpgradeFailure"
	PluginInstanceInternalError         = "PluginInstanceInternalError"
)
View Source
const (

	// 文件过大
	FileTooLarge = "FileTooLarge"

	// 文件上传失败
	FileUploadFailed = "FileUploadFailed"

	// 文件格式不正确
	FileMalformed = "FileMalformed"

	// 文件解压失败
	FileUnzipFailed = "FileUnzipFailed"

	// 加载配置文件失败
	LoadYamlConfigFailed = "LoadYamlConfig"

	// 文件元数据错误
	ErrorMetaData = "ErrorMetaData"

	// 保存到数据库失败
	SaveToDBFailed = "SaveToDBFailed"

	// 插件文件不存在
	FileNoExist = "FileNoExist"

	// 插件包已存在
	FileAlreadyExist = "FileAlreadyExist"

	// 未找到该实例
	InstanceNotFound = "InstanceNotFound"

	// 未找到Host
	HostNotFound = "HostNotFound"

	// 未找到package
	PackageNotFound = "PackageNotFound"

	// 语言不一致
	LanguageDisMatch = "LanguageDisMatch"

	// 语言版本不一致
	LanguageVersionDisMatch = "LanguageVersionDisMatch"

	// Host语言版本不一致
	HostLanguageVersionDisMatch = "HostLanguageVersionDisMatch"

	// 已经卸载
	PluginAlreadyUninstall = "PluginAlreadyUninstall"

	// 插件已安装
	PluginAlreadyInstall = "PluginAlreadyInstall"

	// 插件配置文件解析失败
	PluginConfigFileParseFailed = "PluginConfigFileParseFailed"

	// 插件接口调用失败
	CallPluginFailed = "CallPluginFailed"
)
View Source
const (
	InstanceUUID = "instance_uuid"
	AppUUID      = "app_uuid"
	AppVersion   = "app_version"
)

Variables

View Source
var (
	DefaultStatusCodeBinding = map[string]int{
		AccessDenied:                        http.StatusForbidden,
		AlreadyExists:                       http.StatusConflict,
		StatusError:                         http.StatusConflict,
		AuthFailure:                         http.StatusUnauthorized,
		BadConfig:                           http.StatusInternalServerError,
		Blocked:                             http.StatusForbidden,
		ConstraintViolation:                 http.StatusForbidden,
		CorruptedData:                       http.StatusInternalServerError,
		Gone:                                http.StatusGone,
		InUse:                               http.StatusBadRequest,
		InvalidEnum:                         http.StatusInternalServerError,
		InvalidParameter:                    http.StatusBadRequest,
		KeyConflict:                         http.StatusInternalServerError,
		LimitExceeded:                       http.StatusForbidden,
		MissingParameter:                    http.StatusBadRequest,
		NotFound:                            http.StatusNotFound,
		Deleted:                             http.StatusInternalServerError,
		SourceDeleted:                       http.StatusInternalServerError,
		OK:                                  http.StatusOK,
		PermissionDenied:                    http.StatusForbidden,
		RedisError:                          http.StatusInternalServerError,
		ServerError:                         http.StatusInternalServerError,
		SQLError:                            http.StatusInternalServerError,
		Timeout:                             http.StatusBadRequest,
		TypeMismatch:                        http.StatusInternalServerError,
		UnexpectedArguments:                 http.StatusInternalServerError,
		UnknownError:                        http.StatusInternalServerError,
		VerificationFailure:                 http.StatusBadRequest,
		InvalidFileExt:                      http.StatusBadRequest,
		CallPluginFailure:                   http.StatusBadRequest,
		PluginAlreadyRunning:                http.StatusBadRequest,
		PluginAlreadyStop:                   http.StatusBadRequest,
		GetPluginMessageFailure:             http.StatusBadRequest,
		PluginInstanceInstallationFailure:   http.StatusBadRequest,
		PluginInstanceUninstallationFailure: http.StatusBadRequest,
		PluginInstanceUploadFailure:         http.StatusBadRequest,
		PluginInstanceEnableFailure:         http.StatusBadRequest,
		PluginInstanceDisableFailure:        http.StatusBadRequest,
		PluginInstanceUpgradeFailure:        http.StatusBadRequest,
		PluginInstanceInternalError:         http.StatusInternalServerError,
	}
)

Functions

func ErrorStack

func ErrorStack(err error) string

func Errorf

func Errorf(code string, format string, args ...interface{}) error

根据错误码生成一个错误,并加入自定义信息

func MissingParameterError

func MissingParameterError(model string, field string) error

func New

func New(codeparts ...string) error

eg. err := errors.New("InvalidParameter", "Task.Summary", "TooLong")

func PluginCallError

func PluginCallError(model string, field string) error

func PluginDisableError

func PluginDisableError(reason string) error

func PluginEnableError

func PluginEnableError(reason string) error

func PluginInstallError

func PluginInstallError(reason string) error

func PluginMessageError

func PluginMessageError(reason string) error

func PluginUninstallError

func PluginUninstallError(reason string) error

func PluginUpgradeError

func PluginUpgradeError(reason string) error

func PluginUploadError

func PluginUploadError(reason string) error

func Trace

func Trace(other error) error

从里向外原样返回错误时,必须调用这个方法,以记录里层错误的栈信息 ex:

if err := SomeFunc(); err != nil {
    return errors.Trace(err)
}

func TypeMismatchError

func TypeMismatchError(value interface{}, expectedTypes ...string) error

生成 TypeMismatch 错误

func WithValue

func WithValue(err error, key string, value interface{}) error

额外指定 error 的自定义字段

func Wrap

func Wrap(other error, err error) error

在现有错误的基础上包装一层错误 eg: err := tx.Exec(sql, args...)

if err != nil {
    return errors.Wrap(err, errors.New(errors.SQLError))
}

Types

type Err

type Err struct {
	*jujuerrors.Err
	Code string
	// contains filtered or unexported fields
}

func (*Err) HttpStatus

func (e *Err) HttpStatus() int

获取错误对应的 http 状态码

func (*Err) IntValue

func (e *Err) IntValue(key string) (int, bool)

获取 int 类型的自定义数据

func (*Err) SetValue

func (e *Err) SetValue(key string, value interface{})

设置自定义数据,设置的数据会返回给客户端

func (*Err) StringValue

func (e *Err) StringValue(key string) (string, bool)

获取 string 类型的自定义数据

func (*Err) Value

func (e *Err) Value(key string) (interface{}, bool)

获取自定义数据

func (*Err) Values

func (e *Err) Values() map[string]interface{}

获取所有自定义数据

type ErrPayload

type ErrPayload struct {
	Code       string
	Desc       string
	HttpStatus int
	Values     map[string]interface{}
}

func NewErrPayload

func NewErrPayload(err error) *ErrPayload

func (*ErrPayload) MarshalJSON

func (p *ErrPayload) MarshalJSON() ([]byte, error)

func (*ErrPayload) UnmarshalJSON

func (p *ErrPayload) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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