errors

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: MIT Imports: 6 Imported by: 0

README

errors - apperrors

Custom app errors has support for github.com/pkg/errors.

Documentation

Index

Constants

View Source
const MaxStackTraceLimit = 5

MaxStackTraceLimit allows to print only max 5 frames

Variables

View Source
var (
	NoActiveSubscription = ErrorCode{
		// contains filtered or unexported fields
	}
)

All the defined Internal ErrorCodes

Functions

func Errorf

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

Errorf github.com/pkg/errors wraper Errorf formats according to a format specifier and returns the string as a value that satisfies error. Errorf also records the stack trace at the point it was called.

func New

func New(message string) error

New github.com/pkg/errors wraper New returns an error with the supplied message. New also records the stack trace at the point it was called.

func Wrap

func Wrap(err error, message string) error

Wrap github.com/pkg/errors.Wrap Wrap returns an error annotating err with a stack trace at the point Wrap is called, and the supplied message. If err is nil, Wrap returns nil.

func Wrapf

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

Wrapf github.com/pkg/errors.Wrapf Wrapf returns an error annotating err with a stack trace at the point Wrapf is called, and the format specifier. If err is nil, Wrapf returns nil.

Types

type AppError

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

AppError struct holds the value of HTTP status code and custom error message. https://go.dev/blog/error-handling-and-go

func BadRequest

func BadRequest(message string) *AppError

BadRequest will return `http.StatusBadRequest` with custom message.

func Conflict

func Conflict(message string) *AppError

Conflict will return `http.StatusConflict` with custom message.

func Forbidden

func Forbidden(message string) *AppError

Forbidden will return `http.StatusForbidden` with custom message.

func Gone added in v1.0.3

func Gone(message string) *AppError

Gone will return `http.StatusGone` with custom message.

func InternalServer

func InternalServer(message string) *AppError

InternalServer will return `http.StatusInternalServerError` with custom message.

func InternalServerStd

func InternalServerStd() *AppError

InternalServerStd will return `http.StatusInternalServerError` with static message.

func InvalidKey added in v1.0.2

func InvalidKey(val, key string) *AppError

InvalidKey returns new error with custom error message

func KeyRequired

func KeyRequired(key string) *AppError

KeyRequired returns new error with custom error message

func NewAppError

func NewAppError(status int, msg string) *AppError

NewAppError returns the new apperror object

func NotFound

func NotFound(message string) *AppError

NotFound will return `http.StatusNotFound` with custom message.

func PaymentRequired

func PaymentRequired(message string) *AppError

PaymentRequired will return `http.StatusPaymentRequired` with custom message.

func TooEarly added in v1.0.3

func TooEarly(message string) *AppError

TooEarly will return `http.StatusTooEarly` with custom message.

func TooManyRequests

func TooManyRequests(message string) *AppError

TooManyRequests will return `http.StatusTooManyRequests` with custom message.

func Unauthorized

func Unauthorized(message string) *AppError

Unauthorized will return `http.StatusUnauthorized` with custom message.

func UnprocessableEntity

func UnprocessableEntity(message string) *AppError

UnprocessableEntity will return `http.StatusUnprocessableEntity` with custom message.

func (*AppError) AddConflictData

func (err *AppError) AddConflictData(data interface{}) *AppError

AddConflictData add extra conflict error information. This will be sent in meta

func (*AppError) AddDebug

func (err *AppError) AddDebug(cause error) *AppError

AddDebug method is used to add a debug error which will be printed during the error execution if it is not nil. This is purely for developers debugging purposes This can be overridden N times in the entire lifecycle to wrap stacktraces

expects cause of return type of wraped github.com/pkg/errors

func (*AppError) AddDebugf

func (err *AppError) AddDebugf(format string, a ...interface{}) *AppError

AddDebugf is a helper function which calls fmt.Errorf internally for the error which is added a Debug

func (*AppError) AddErrorDetail

func (err *AppError) AddErrorDetail(d *Details) *AppError

AddErrorDetail is used to add the error_details fields in the metadata object of the response. This field will be empty if ErrorDetail is not configured.

func (*AppError) DebugError

func (err *AppError) DebugError() string

DebugError returns the detailed warped error message if present, else returns default msg.

func (*AppError) Error

func (err *AppError) Error() string

Error implements error interface

func (*AppError) GetConflictData

func (err *AppError) GetConflictData() interface{}

GetConflictData returns the conflict data if present

func (*AppError) GetDebug

func (err *AppError) GetDebug() error

GetDebug returns the debug error if presents else returns new error of the message

func (*AppError) GetStatus

func (err *AppError) GetStatus() int

GetStatus returns the status code of the apperror

func (*AppError) IsBadRequest

func (err *AppError) IsBadRequest() bool

IsBadRequest should return true if HTTP status of an error is 400.

func (*AppError) IsForbidden

func (err *AppError) IsForbidden() bool

IsForbidden should return true if HTTP status of an error is 403.

func (*AppError) IsInternalError

func (err *AppError) IsInternalError() bool

IsInternalError should return true if HTTP status of an error is >= 5XX.

func (*AppError) IsInternalServerError

func (err *AppError) IsInternalServerError() bool

IsInternalServerError should return true if HTTP status of an error is 500.

func (*AppError) IsStatusNotFound

func (err *AppError) IsStatusNotFound() bool

IsStatusNotFound should return true if HTTP status of an error is 404.

func (*AppError) Log

func (err *AppError) Log()

Log logs the app error to stdout log stack trace

func (*AppError) MarshalJSON

func (err *AppError) MarshalJSON() ([]byte, error)

MarshalJSON converts the AppError struct to JSON bytes

func (*AppError) NotNil

func (err *AppError) NotNil() bool

NotNil checks if the app errors is not nil or not

func (*AppError) OverwriteStatusCode

func (err *AppError) OverwriteStatusCode()

OverwriteStatusCode change the status code to 460, if the error contains context canceled.

func (*AppError) UnmarshalJSON

func (err *AppError) UnmarshalJSON(b []byte) error

UnmarshalJSON convets a byte back to the AppError struct

func (*AppError) UpdateMsg

func (err *AppError) UpdateMsg(msg string)

UpdateMsg lets overrides the error message will be send to the client

func (*AppError) UpdateStatus

func (err *AppError) UpdateStatus(statusCode int)

UpdateStatus lets overrides the status code which is passed

func (*AppError) WithNoLog added in v1.0.3

func (err *AppError) WithNoLog() *AppError

WithNoLog enables the no logging for this particular error. this can be invoked at the handler level return err.WithNoLog()

func (*AppError) Wrap

func (err *AppError) Wrap(cause error, message string) *AppError

Wrap github.com/pkg/errors.Wrap Wrap returns an error annotating err with a stack trace at the point Wrap is called, and the supplied message. If err is nil, Wrap returns nil.

func (*AppError) Wrapd

func (err *AppError) Wrapd(message string) *AppError

Wrapd github.com/pkg/errors.Wrap Wrap returns an error annotating err with a stack trace at the point Wrap is called, and the supplied message. If err is nil, Wrap returns nil.

func (*AppError) Wrapf

func (err *AppError) Wrapf(cause error, format string, args ...interface{}) *AppError

Wrapf github.com/pkg/errors.Wrapf Wrapf returns an error annotating err with a stack trace at the point Wrapf is called, and the format specifier. If err is nil, Wrapf returns nil.

type Details

type Details struct {
	Code        string `json:"code"`
	Description string `json:"description,omitempty"`
	Link        string `json:"link,omitempty"`
}

Details struct contains the application logic specific internal error codes, readable message and a link to a support doc.

type ErrorCode

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

ErrorCode is a enum type where all the platform error codes are defined.

func (ErrorCode) Form

func (e ErrorCode) Form(desc string) *Details

Form forms the Details struct for the error code receiver.

Jump to

Keyboard shortcuts

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