errors

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2017 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ReasonInternal is a type about internal errors
	ReasonInternal = "ReasonInternal"
	// ReasonRequest is a type about request errors
	ReasonRequest = "ReasonRequest"
)

defines reason types

Variables

View Source
var (
	// ErrorUnknownRequest defines unknown error when failed to handle a request
	ErrorUnknownRequest = NewFormatError(http.StatusBadRequest, ReasonRequest, "%s")
	// ErrorParamTypeError defines param type error
	ErrorParamTypeError = NewFormatError(http.StatusBadRequest, ReasonRequest, "param %s should be %s, but got %s")
	// ErrorParamNotFound defines request param error
	ErrorParamNotFound = NewFormatError(http.StatusBadRequest, ReasonRequest, "can't find param %s in request")
	// ErrorUrlParamNotFound defines request url query param error
	ErrorUrlParamNotFound = NewFormatError(http.StatusBadRequest, ReasonRequest, "can't find param %s in request url query")
	// ErrorHeaderNotFound defines request header error
	ErrorHeaderParamNotFound = NewFormatError(http.StatusBadRequest, ReasonRequest, "can't find param %s in request header")
	// ErrorValidationFailed defines validation failed error
	ErrorValidationFailed = NewFormatError(http.StatusBadRequest, ReasonRequest, "failed to validate %s: %s")
	// ErrorContentNotFound defines not found error
	ErrorContentNotFound = NewFormatError(http.StatusNotFound, ReasonRequest, "content %s not found")
	// ErrorQuotaExceeded defines quota exceeded error, creating or updating was not allowed
	ErrorQuotaExceeded          = NewFormatError(http.StatusForbidden, ReasonRequest, "%s quota exceeded")
	ErrorAlreadyExist           = NewFormatError(http.StatusConflict, ReasonRequest, "conflict: %s already exist")
	ErrorAuthenticationRequired = NewFormatError(http.StatusProxyAuthRequired, ReasonRequest, "authentication required")

	// ErrorInternalTypeError defines internal type error
	ErrorInternalTypeError = NewFormatError(http.StatusInternalServerError, ReasonInternal, "type of %s should be %s, but got %s")
	// ErrorUnknownNotFoundError defines not found error that we can't find a reason
	ErrorUnknownNotFoundError = NewFormatError(http.StatusInternalServerError, ReasonInternal, "content %s not found, may be it's a serious error")
	// ErrorUnknownInternal defines any internal error and not one of above errors
	ErrorUnknownInternal = NewFormatError(http.StatusInternalServerError, ReasonInternal, "unknown error: %s")

	// ErrorCreateFailed defines error that failed creating of something.
	ErrorCreateFailed = NewFormatError(http.StatusBadRequest, ReasonInternal, "failed to create %s: %s")
	// ErrorUpdateFailed defines error that failed updating of something.
	ErrorUpdateFailed = NewFormatError(http.StatusBadRequest, ReasonInternal, "failed to update %s: %s")
	// ErrorDeleteFailed defines error that failed deleting of something.
	ErrorDeleteFailed = NewFormatError(http.StatusBadRequest, ReasonInternal, "failed to delete %s: %s")
	// ErrorGetFailed defines error that failed geting of something.
	ErrorGetFailed = NewFormatError(http.StatusBadRequest, ReasonInternal, "failed to get %s: %s")
	// ErrorListFailed defines error that failed listing of something.
	ErrorListFailed = NewFormatError(http.StatusBadRequest, ReasonInternal, "failed to list %s: %s")
)

Functions

func NewCreateError

func NewCreateError(name, errorMessage string) error

func NewDeleteError

func NewDeleteError(name, errorMessage string) error

func NewErrorID

func NewErrorID() int

NewErrorID generates an unique id in current runtime

func NewGetError

func NewGetError(name, errorMessage string) error

func NewListError

func NewListError(name, errorMessage string) error

func NewNotFoundError

func NewNotFoundError(name string) error

func NewUpdateError

func NewUpdateError(name, errorMessage string) error

func NewValidateError

func NewValidateError(name, reason string) error

NewValidateError creates new ErrorValidationFailed

Types

type Error

type Error struct {
	ID      int    `json:"id,omitempty"`
	Code    int    `json:"code,omitempty"`
	Reason  string `json:"reason,omitempty"`
	Message string `json:"message"`
	Detail  string `json:"detail,omitempty"`
	// contains filtered or unexported fields
}

Error defines error with code

func NewFormatError

func NewFormatError(code int, reason string, format string) *Error

NewFormatError creates a format error

func NewStaticError

func NewStaticError(code int, reason string, message string) *Error

NewStaticError creates a static error

func (*Error) AppendErrorDetail

func (r *Error) AppendErrorDetail(b []byte) []byte

AppendErrorDetail returns a byte slice joined err, cmd and pc in ErrorDetail.

func (*Error) Equal

func (e *Error) Equal(err error) bool

Equal returns whether err.ID equal to e.ID

func (*Error) Error

func (e *Error) Error() string

Error returns error reason

func (*Error) ErrorDetail

func (r *Error) ErrorDetail() string

func (*Error) Format

func (e *Error) Format(params ...interface{}) *Error

Format generate an specified error

Jump to

Keyboard shortcuts

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