Documentation ¶
Index ¶
- Variables
- type ErrParams
- type Error
- func As(err error) (*Error, bool)
- func GenerateUnknownError(err error, httpCode ...int) *Error
- func GetErrorWithKV(err Error, key string, value interface{}) *Error
- func GetErrorWithKVPairs(err Error, keys []string, values []interface{}) *Error
- func GetErrorWithMessage(err Error, datas ...ErrParams) *Error
- func New(httpCode int, text string, params ...ErrParams) *Error
- func Wrap(err error, httpCode ...int) (e *Error)
- type JSON
- type StatusCoder
Constants ¶
This section is empty.
Variables ¶
var ErrDatabaseServerError = &Error{ HTTPCode: http.StatusInternalServerError, Err: errors.New("operation database failed"), Code: "INTERNAL_SERVER_ERROR", }
ErrDatabaseServerError internal server error
var ErrForbidden = &Error{ HTTPCode: http.StatusForbidden, Err: errors.New("forbidden"), Code: "ACCESS_IS_FORBIDDEN", }
ErrForbidden access is forbidden
var ErrInternalServerError = &Error{ HTTPCode: http.StatusInternalServerError, Err: errors.New("internal server error"), Code: "INTERNAL_SERVER_ERROR", }
ErrInternalServerError internal server error
var ErrInvalidArguments = &Error{ HTTPCode: http.StatusBadRequest, Err: errors.New("invalid arguments"), Code: "INVALID_ARGUMENTS", }
ErrInvalidArguments invalid arguments
var ErrNotFound = &Error{ HTTPCode: http.StatusNotFound, Err: errors.New("not found"), Code: "NOT_FOUND", }
ErrNotFound not found error
var ErrRequestEntityTooLarge = &Error{ HTTPCode: http.StatusRequestEntityTooLarge, Err: errors.New("request entity too large"), Code: "REQUEST_ENTITY_TOO_LARGE", }
ErrRequestEntityTooLarge request entity too large
http.StatusUnauthorized, Err: errors.New("unauthorized"), Code: "UNAUTHORIZED", }HTTPCode:
ErrUnauthorized unauthorized
Functions ¶
This section is empty.
Types ¶
type Error ¶
Error custom error
func GenerateUnknownError ¶
GenerateUnknownError return a unknown error
func GetErrorWithKV ¶
GetErrorWithKV new error from exist and modify message with key/value
func GetErrorWithKVPairs ¶
GetErrorWithKVPairs new error from exist error and new message with key/value pairs
func GetErrorWithMessage ¶
GetErrorWithMessage new error from exist error, but you need a data
func (Error) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
type JSON ¶
type JSON struct { HTTPCode int `json:"-"` Err error `json:"-"` Code string `json:"code"` Message ErrParams `json:"message"` }
JSON custom error json struct
type StatusCoder ¶
type StatusCoder interface {
StatusCode() int
}
StatusCoder is a interface for http status code