errors

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

GOMAXHUB / errors

errors.jpg Friendly and convenient library for working with errors in micro-services.

Features

  • Wrap/Wrapf any error with custom message and codes mapping
  • use NewBuilder() to create custom errors wrapper for your service needs
  • describe meaning of any status code using WithErrorsCodesMapping option
  • add any attributes to any error using WithErrorAttributes option (service name, service version, etc.)
  • enable stacktrace for your errors using WithStackTrace option

Attention

  • please, check examples in repository

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatError

func FormatError(f Formatter, s fmt.State, verb rune)

func NewBuilder

func NewBuilder(options ...func(*builder)) *builder

func NewHTTPError

func NewHTTPError(statusCode int, code string, description string) error

func Unwrap

func Unwrap(err error) error

func WithAttributes

func WithAttributes(attrs map[string]any) func(*builder)

func WithErrorsCodesMapping

func WithErrorsCodesMapping(mapping map[int]string) func(*builder)

func WithStack

func WithStack() func(*builder)

func Wrap

func Wrap(err error, message string) error

Wrap error with message and caller.

func Wrapf

func Wrapf(err error, format string, a ...interface{}) error

Wrapf wraps error with formatted message and caller.

Types

type Formatter

type Formatter interface {
	error

	FormatError(p Printer) (next error)
}

type Frame

type Frame struct {
	// contains filtered or unexported fields
}

func Caller

func Caller(skip int) Frame

func (Frame) Format

func (f Frame) Format(p Printer)

func (Frame) Location

func (f Frame) Location() (function, file string, line int)

type HTTPError

type HTTPError interface {
	Error() string
	StatusCode() int   // actual HTTP status code
	ErrorCode() string // error code returned in response body from CC or UAA
}

type Printer

type Printer interface {
	// Print appends args to the message output.
	Print(args ...interface{})

	// Printf writes a formatted string.
	Printf(format string, args ...interface{})

	// Detail reports whether error detail is requested.
	// After the first call to Detail, all text written to the Printer
	// is formatted as additional detail, or ignored when
	// detail has not been requested.
	// If Detail returns false, the caller can avoid printing the detail at all.
	Detail() bool
}

type Wrapper

type Wrapper interface {
	Unwrap() error
}

Directories

Path Synopsis
examples
builder command
http command
simple command

Jump to

Keyboard shortcuts

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