errors

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(code Code, msg string, args ...any) error

New creates a new error and returns it

func Wrap

func Wrap(err error, code Code, msg string, args ...any) error

Wrap Wraps the given error and returns a new one. If the error is nil, it will return nil

Types

type Code

type Code int

Code is a code associated with an error

const (
	Internal     Code = http.StatusInternalServerError
	NotFound     Code = http.StatusNotFound
	Forbidden    Code = http.StatusForbidden
	Validation   Code = http.StatusBadRequest
	Unauthorized Code = http.StatusUnauthorized
)

type Error

type Error struct {
	Code     Code     `json:"code"`
	Messages []string `json:"messages,omitempty"`
	Err      string   `json:"err,omitempty"`
}

Error is a custom error

func Extract

func Extract(err error) *Error

Extract extracts the custom Error from the given error. If the error is nil, nil will be returned

func (*Error) Error

func (e *Error) Error() string

Error returns the Error as a json string

func (*Error) RemoveError

func (e *Error) RemoveError() *Error

RemoveError removes the error from the Error and leaves it's messages and code

Jump to

Keyboard shortcuts

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