errors

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorMessage

func ErrorMessage(err error) string

ErrorMessage extracts a specified error response to be returned to the caller if present, otherwise returns an empty string

func LogData

func LogData(err error) log.Data

LogData returns logData for an error if there is any. This is used to extract log.Data embedded in an error if it implements the dataLogger interface

func StackTrace

func StackTrace(err error) []log.EventStackTrace

StackTrace recursively unwraps the error looking for the deepest level at which the error was wrapped with a stack trace from github.com/pkg/errors (or conforms to the StackTracer interface) and returns the slice of stack frames. These can are of type log.go/EventStackTrace so can be used directly with log.Go's available API to preserve the correct error logging format

func StatusCode

func StatusCode(err error) int

StatusCode attempts to extract a status code from an error, or returns 0 if not found

func UnwrapErrorMessage added in v2.2.0

func UnwrapErrorMessage(err error) string

UnwrapErrorMessage is a callback function that allows you to extract an error message from an error. If the error message returned is an empty string, UnwrapErrorMessage will attempt to recursively unwrap the error until a non-empty string is returned. If no message is returned it will return the original error's error string as default.

func UnwrapLogData

func UnwrapLogData(err error) log.Data

UnwrapLogData recursively unwraps logData from an error. This allows an error to be wrapped with log.Data at each level of the call stack, and then extracted and combined here as a single log.Data entry. This allows us to log errors only once but maintain the context provided by log.Data at each level.

func UnwrapStatusCode

func UnwrapStatusCode(err error) int

UnwrapStatusCode is a callback function that allows you to extract a status code from an error. If the status code returned is 0, statusCode will attempt to recursively unwrap the error until a non-zero code is returned. If no more code is embedded it will return status 500 as default.

Types

This section is empty.

Jump to

Keyboard shortcuts

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