httperrors

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2025 License: MIT Imports: 8 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 Error

type Error struct {
	HTTPCode int
	Err      error
	Code     string

	Meta   any
	Fields map[string]any
}

Error custom error

func As

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

As is errors.As

func New

func New(httpCode int, format string, a ...any) *Error

New returns a new http Error object

func (*Error) AddField

func (e *Error) AddField(key string, value any) *Error

AddField adds field

func (*Error) AddFields

func (e *Error) AddFields(fields map[string]any) *Error

AddFields adds fields

func (*Error) Clone

func (e *Error) Clone() *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) HasField

func (e *Error) HasField(key string) bool

HasField checks if field exists

func (*Error) Is

func (e *Error) Is(target error) bool

func (Error) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (*Error) SetCode

func (e *Error) SetCode(code string) *Error

SetCode sets the error's code.

func (*Error) SetHTTPCode

func (e *Error) SetHTTPCode(httpCode int) *Error

SetHTTPCode sets the error's http code.

func (*Error) SetMeta

func (e *Error) SetMeta(data any) *Error

SetMeta sets the error's meta data.

func (*Error) StatusCode

func (e *Error) StatusCode() int

StatusCode return http status code

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the wrapped error, to allow interoperability with errors.Is(), errors.As() and errors.Unwrap()

Jump to

Keyboard shortcuts

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