errors

package
v0.3.9 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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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