errors

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2021 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	//2xx
	StatusOK = http.StatusOK

	//4xx
	StatusBadRequest      = http.StatusBadRequest
	StatusUnauthorized    = http.StatusUnauthorized
	StatusPaymentRequired = http.StatusPaymentRequired
	StatusForbidden       = http.StatusForbidden
	StatusNotFound        = http.StatusNotFound

	//5xx
	StatusInternalServerError = http.StatusInternalServerError
	StatusNotImplemented      = http.StatusNotImplemented
)

Variables

This section is empty.

Functions

func LastResortHandler

func LastResortHandler(loc string)

LastResortHandler - Setup at start of program to capture panics not solved elsewhere to enable logging prior to program close down

func LastResortHandlerWithContext

func LastResortHandlerWithContext(ctx context.Context, loc string)

LastResortHandlerWithContext - Setup at start of program to capture panics not solved elsewhere to enable logging prior to program close down

func NewClientError

func NewClientError(err string) error

NewClientError - returns a default BadRequest denoting a client user error

func NewSystemError

func NewSystemError(ctx context.Context, err string) error

NewSystemError - returns a default InternalServerError denoting an implementation issue

func NewValidationError

func NewValidationError(err string) error

NewValidationError - returns a default StatusOK error denoting a user validation error

func SetupEventing

func SetupEventing()

SetupEventing - Configures your eventing if enabled via env variable: ERROR_EVENTING = true

func WriteDeveloperEvent

func WriteDeveloperEvent(ctx context.Context, msg string)

WriteDeveloperEvent - Sends message to sentry to enable a developer to pick up and fix a known issue where auto-fix is not yet known To be used when client should not receive error however developer MUST fix it to restore full client functionality

Types

type Error

type Error struct {
	ErrorType        int
	DeveloperMessage string
	UserMessage      string
	ErrorCode        string
	MoreInfo         string
}

Error contains - - errorType - from the const list, the type of error this represents. The New constructors set reasonable default status that can be replaced if appropriate. - developerMessage - message that may help the developer use the API correctly

  • userMessage - message for the end user display
  • errorCode - error to report to support or standardized user error code as applicable
  • moreInfo - link to documentation with more info

- If eventing is enabled, event will be generated upon creation. For now, have only setup for system errors to event. For example, validation errors or client errors will not event. Can change to config in the future

Future TODO:

  • add correlation id into errorCode or moreInfo when reporting

func NewError

func NewError(ctx context.Context, err error) Error

NewError - returns a full core error struct from the default error type. Type defafults to server error Because this takes an error, the assumption is the underlying type is preferred to minimize type conversions in calling code

func (Error) Error

func (err Error) Error() string

Error - implements the error interface

Jump to

Keyboard shortcuts

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