serrors

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: MIT Imports: 4 Imported by: 0

README

serrors

simple error handling for golang

usage

wrap errors
func otherMethod() error {
	return errors.New("unimplemented")
}

func someMethod() error {
	// wrap error for displaying stack trace
	return serrors.Wrap(otherMethod())
}

func main() {
	if err := someMethod(); err != nil {
		// show stack trace by Printf
		log.Fatalf("%+v", err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Is

func Is(err, target error) bool

func IsStatus

func IsStatus(err error, status int) bool

func RequestError

func RequestError(err error, code int) error

func ResponseError

func ResponseError(err error, code int) error

Types

type AppError

type AppError interface {
	Error() string
	Unwrap() error
	Format(s fmt.State, v rune)
	FormatError(p xerrors.Printer) error
	AddData(field string, data interface{}) AppError

	BadRequest() AppError
	Unauthorized() AppError
	NotFound() AppError
	InternalServerError() AppError

	New(msg ...string) AppError
	Errorf(format string, args ...interface{}) AppError
	Wrap(err error, msg ...string) AppError
	Code() int
	Status() int
	Is(err error) bool
	IsStatus(status int) bool
}

func AsAppError

func AsAppError(err error) AppError

func BadRequestf

func BadRequestf(format string, args ...any) AppError

func Errorf

func Errorf(format string, args ...interface{}) AppError

func Forbiddenf

func Forbiddenf(format string, args ...interface{}) AppError

func New

func New(msg string) AppError

func NotFoundf

func NotFoundf(format string, args ...interface{}) AppError

func Wrap

func Wrap(err error, msg ...string) AppError

Jump to

Keyboard shortcuts

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