err

package
v0.0.0-...-abd2dae Latest Latest
Warning

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

Go to latest
Published: May 15, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//ErrInternalServer type internal server error
	ErrInternalServer = 0
	//ErrBadRequest error type bad request
	ErrBadRequest = 1
)
View Source
const (
	InternalServerName        = "internal_server_error"
	InternalServerDescription = "The server is unable to complete your request"
)

Common internal server error message

View Source
const (
	UnauthorizedErrorName        = "access_denied"
	UnauthorizedErrorDescription = "Authorization failed by filter."
)

Common error unautorized

Variables

View Source
var (
	ErrKeyExists    = errors.New("Key already exists")
	ErrKeyNotFound  = errors.New("Key not found")
	ErrKeyDuplicate = errors.New("Key already exists")
)

error list

View Source
var DefaultBadRequest = ErrorFormat{
	ErrorName:        "bad_request",
	ErrorDescription: "Your request resulted in error",
}

Common bad request error message

View Source
var (
	ErrCommon = errors.New("A failure occurred")
)

Functions

func CustomWrap

func CustomWrap(err error, args ...string) error

CustomWrap custom error wrap without flag example result : <args> : <err>

func CustomWrapF

func CustomWrapF(err error, flag string, args ...string) error

CustomWrapF custom error wrap with flag example result : [<flag>] <args> : <err>

Types

type ErrorFormat

type ErrorFormat struct {
	ErrorName        string `json:"error_name"`
	ErrorDescription string `json:"error_description"`
}

An ErrorFormat represents an error message format and code that we used.

type ErrorMessage

type ErrorMessage struct {
	ErrorList []*ErrorFormat `json:"error_list"`
	Code      int            `json:"code"`
}

An ErrorMessage represents an error message format and list of error.

func NewErrorMessage

func NewErrorMessage() *ErrorMessage

Create new error message

func SetDefaultNewBadRequest

func SetDefaultNewBadRequest() *ErrorMessage

func SetDefaultUnauthorized

func SetDefaultUnauthorized() *ErrorMessage

SetNewUnauthorizedError is function return new error message with unauthorized error code(400). It support to set error name and error description

func SetNewBadRequest

func SetNewBadRequest(errorName, errDesc string) *ErrorMessage

SetNewBadRequest is function return new error message with bad request standard code(400). It support to set error name and error description

func SetNewBadRequestByFormat

func SetNewBadRequestByFormat(ef *ErrorFormat) *ErrorMessage

SetNewBadRequest is function return new error message with bad request standard code(400). It support to set error name and error description using error format

func SetNewError

func SetNewError(code int, errorName, errDesc string) *ErrorMessage

SetNewError is function return new error message. It support to set code, error name, and error description

func SetNewInternalError

func SetNewInternalError() *ErrorMessage

SetNewInternalError is function return new error message with internal server error standard code(500).

func SetNewUnauthorizedError

func SetNewUnauthorizedError(errorName, errDesc string) *ErrorMessage

SetNewUnauthorizedError is function return new error message with unauthorized error code(400). It support to set error name and error description

func (*ErrorMessage) Append

func (errorMessage *ErrorMessage) Append(errorName, errDesc string) *ErrorMessage

Append is function add error to existing error message. It support to set error name and error description.

func (*ErrorMessage) AppendFormat

func (errorMessage *ErrorMessage) AppendFormat(ef *ErrorFormat) *ErrorMessage

AppendFormat is function add error to existing error message. It support to set error name and error description using error format

func (*ErrorMessage) Error

func (errorMessage *ErrorMessage) Error() string

Error to implement error interface

func (*ErrorMessage) GetCode

func (errorMessage *ErrorMessage) GetCode() int

GetCode is function to get code.

func (*ErrorMessage) GetListError

func (errorMessage *ErrorMessage) GetListError() []*ErrorFormat

GetListError is function to get list error message.

func (*ErrorMessage) Marshal

func (errorMessage *ErrorMessage) Marshal() []byte

Get error byte

func (*ErrorMessage) SetBadRequest

func (em *ErrorMessage) SetBadRequest() *ErrorMessage

Set bad request

func (*ErrorMessage) ToString

func (errorMessage *ErrorMessage) ToString() string

Get string

Jump to

Keyboard shortcuts

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