httperrors

package
v0.0.0-...-df360ae Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDatabaseServerError = &Error{
	HTTPCode: http.StatusInternalServerError,
	Err:      errors.New("operation database failed"),
	Code:     "INTERNAL_SERVER_ERROR",
}

ErrDatabaseServerError internal server error

View Source
var ErrForbidden = &Error{
	HTTPCode: http.StatusForbidden,
	Err:      errors.New("forbidden"),
	Code:     "ACCESS_IS_FORBIDDEN",
}

ErrForbidden access is forbidden

View Source
var ErrInternalServerError = &Error{
	HTTPCode: http.StatusInternalServerError,
	Err:      errors.New("internal server error"),
	Code:     "INTERNAL_SERVER_ERROR",
}

ErrInternalServerError internal server error

View Source
var ErrInvalidArguments = &Error{
	HTTPCode: http.StatusBadRequest,
	Err:      errors.New("invalid arguments"),
	Code:     "INVALID_ARGUMENTS",
}

ErrInvalidArguments invalid arguments

View Source
var ErrNotFound = &Error{
	HTTPCode: http.StatusNotFound,
	Err:      errors.New("not found"),
	Code:     "NOT_FOUND",
}

ErrNotFound not found error

View Source
var ErrRequestEntityTooLarge = &Error{
	HTTPCode: http.StatusRequestEntityTooLarge,
	Err:      errors.New("request entity too large"),
	Code:     "REQUEST_ENTITY_TOO_LARGE",
}

ErrRequestEntityTooLarge request entity too large

View Source
var ErrUnauthorized = &Error{
	HTTPCode: http.StatusUnauthorized,
	Err:      errors.New("unauthorized"),
	Code:     "UNAUTHORIZED",
}

ErrUnauthorized unauthorized

Functions

This section is empty.

Types

type ErrParams

type ErrParams map[string]interface{}

ErrParams error params

type Error

type Error struct {
	HTTPCode int
	Err      error
	Code     string
	Message  ErrParams
}

Error custom error

func As

func As(err error) (*Error, bool)

As is errors.As

func GenerateUnknownError

func GenerateUnknownError(err error, httpCode ...int) *Error

GenerateUnknownError return a unknown error

func GetErrorWithKV

func GetErrorWithKV(err Error, key string, value interface{}) *Error

GetErrorWithKV new error from exist and modify message with key/value

func GetErrorWithKVPairs

func GetErrorWithKVPairs(err Error, keys []string, values []interface{}) *Error

GetErrorWithKVPairs new error from exist error and new message with key/value pairs

func GetErrorWithMessage

func GetErrorWithMessage(err Error, datas ...ErrParams) *Error

GetErrorWithMessage new error from exist error, but you need a data

func New

func New(httpCode int, text string, params ...ErrParams) *Error

New returns a new http Error object

func Wrap

func Wrap(err error, httpCode ...int) (e *Error)

Wrap booboo error wrapper helper

func (*Error) Error

func (e *Error) Error() string

func (Error) MarshalJSON

func (e Error) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Error) StatusCode

func (e *Error) StatusCode() int

StatusCode return http status code

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap method

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

Jump to

Keyboard shortcuts

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