xerror

package
Version: v0.0.0-...-5a98790 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package xerror helps standardizing the errors through the application.

Credits: https://middlemost.com/failure-is-your-domain/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Invalid

func Invalid(op, message string, previous error) error

Invalid returns a xerror.Error.

Should be used when an input is wrong.

func Message

func Message(err error) string

Message returns the human-readable message of the error, if available. Otherwise returns a generic error message.

func New

func New(op string, previous error) error

New returns a xerror.Error.

Should be used for wrapping an error at the end of a function.

func Op

func Op(err error) string

Op returns the logical operation of the error, if available. Otherwise returns an empty string.

func Timeout

func Timeout(op, message string, previous error) error

Timeout returns a xerror.Error.

Should be used when a timeout occurs.

Types

type Error

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

Error defines our standard application error.

func (Error) Error

func (e Error) Error() string

Error returns the string representation of the error message.

type ErrorCode

type ErrorCode string

ErrorCode is machine-readable error code.

const (
	// InternalCode is an internal error.
	InternalCode ErrorCode = "internal"
	// InvalidCode occurs when a validation
	// failed.
	InvalidCode ErrorCode = "invalid"
	// TimeoutCode occurs when something
	// timed out.
	TimeoutCode ErrorCode = "timeout"
)

func Code

func Code(err error) ErrorCode

Code returns the code of the root error, if available. Otherwise returns InternalCode.

Source Files

Jump to

Keyboard shortcuts

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