errs

package
v0.0.0-...-2fa74ab Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserNotFound    = NewCustomError(NotFound, "user not found", nil)
	ErrFindingUsers    = NewCustomError(InternalError, "error finding users", nil)
	ErrFindingUserByID = NewCustomError(InternalError, "error finding user by id", nil)
	ErrCreatingUser    = NewCustomError(InternalError, "error creating user", nil)
	ErrUpdatingUser    = NewCustomError(InternalError, "error updating user", nil)
	ErrDeletingUser    = NewCustomError(InternalError, "error deleting user", nil)
	ErrValidatingUser  = NewCustomError(InvalidFormat, "invalid user", nil)
)

Functions

This section is empty.

Types

type CustomError

type CustomError struct {
	Code    ErrorCode `json:"code"`
	Message string    `json:"message"`
	Err     error     `json:"detail,omitempty"`
}

CustomError represents a more detailed error with a message and code

func NewCustomError

func NewCustomError(code ErrorCode, message string, err error) *CustomError

NewCustomError creates a new CustomError

func (*CustomError) Error

func (e *CustomError) Error() string

Error implements the error interface for CustomError

func (*CustomError) MarshalJSON

func (e *CustomError) MarshalJSON() ([]byte, error)

func (*CustomError) SetDetail

func (e *CustomError) SetDetail(err error) *CustomError

func (*CustomError) SetDetailFromString

func (e *CustomError) SetDetailFromString(err string) *CustomError

func (*CustomError) Unwrap

func (e *CustomError) Unwrap() error

Unwrap allows errors.Is and errors.As to work with CustomError

type ErrorCode

type ErrorCode string
const (
	InvalidFormat ErrorCode = "ERR400"
	NotFound      ErrorCode = "ERR404"
	InternalError ErrorCode = "ERR500"
)

func (ErrorCode) StatusCode

func (ec ErrorCode) StatusCode() int

Jump to

Keyboard shortcuts

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