errors

package
v0.0.0-...-bf83fb3 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownInternalServerError = "01: Unknown Internal Server Error"
	Unauthorized               = "02: Unauthorized"
	Unauthenticated            = "03: Authentication Failed"
	Forbidden                  = "04: Forbidden"
)
View Source
const (
	// PQErr23505UniqueViolation Postgres code for unique violation
	PQErr23505UniqueViolation = "23505"
	// PQErr58030IOError Postgres code for i/o error ("could not write to temporary file")
	PQErr58030IOError = "58030"
	// PQErr42P01 pq: relation "<string>" does not exist
	PQErr42P01 = "42P01"
)

Variables

This section is empty.

Functions

func ContainsError

func ContainsError(err error, msg string) bool

ContainsError checks if the error contains the specified error message

func IsAnyPQError

func IsAnyPQError(err error) bool

IsAnyPQError checks if the passed error is a Postgres error

func IsNoRowsPQError

func IsNoRowsPQError(err error) bool

IsNoRowsPQError returns whether the error is a pg sql no rows found

func IsPQError

func IsPQError(err error, errorCode string) bool

IsPQError checks if the passed error is the specified Postgres error code

func NewErr

func NewErr(err error) error

NewErr returns an error with the friendly user message from an ExtendedError, so it doesn't get logged

func Wrap

func Wrap(err error, debugMsg, userMsg string) error

Wrap checks if the passed error has been wrapped before by this func and either wraps the original error as an ExtendedError or adds the debug message to the already existing ExtendedError's InnerError. It will also overwrite the current ExtendedError's user message if the passed userMsg is not empty i.e. is it an ExtendedError. If not, it will create an ExtendedError, assign the InnerError and UserMsg to it and then return it. If it already is an ExtendedError

Types

type ExtendedError

type ExtendedError struct {
	InnerError error  `json:"innerError"`
	UserMsg    string `json:"userMsg"`

	TruncateXLines int
	// contains filtered or unexported fields
}

ExtendedError is our custom error

var CustomExtendedError *ExtendedError = &ExtendedError{}

CustomExtendedError is the custom error object

func AsExtendedError

func AsExtendedError(err error) (ee *ExtendedError)

AsExtendedError helper function that returns the error as an ExtendedError if it is one. Otherwise it returns nil

func (*ExtendedError) AsError

func (e *ExtendedError) AsError(tgt interface{}) bool

AsError calls errors.As on the original error with the specified target error. If it is the target error, it will set the target as the original error value and return true, otherwise it returns false

func (*ExtendedError) Error

func (e *ExtendedError) Error() string

Error returns the string of the inner error

func (*ExtendedError) IsError

func (e *ExtendedError) IsError(tgt error) bool

IsError checks if the originating error is the specified target

Jump to

Keyboard shortcuts

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