Documentation ¶
Index ¶
- Constants
- Variables
- func Errorf(format string, args ...interface{}) error
- func New(message string) error
- func Wrap(err error, message string) error
- func Wrapf(err error, format string, args ...interface{}) error
- type AppError
- func BadRequest(message string) *AppError
- func Conflict(message string) *AppError
- func Forbidden(message string) *AppError
- func Gone(message string) *AppError
- func InternalServer(message string) *AppError
- func InternalServerStd() *AppError
- func InvalidKey(val, key string) *AppError
- func KeyRequired(key string) *AppError
- func NewAppError(status int, msg string) *AppError
- func NotFound(message string) *AppError
- func PaymentRequired(message string) *AppError
- func TooEarly(message string) *AppError
- func TooManyRequests(message string) *AppError
- func Unauthorized(message string) *AppError
- func UnprocessableEntity(message string) *AppError
- func (err *AppError) AddConflictData(data interface{}) *AppError
- func (err *AppError) AddDebug(cause error) *AppError
- func (err *AppError) AddDebugf(format string, a ...interface{}) *AppError
- func (err *AppError) AddErrorDetail(d *Details) *AppError
- func (err *AppError) DebugError() string
- func (err *AppError) Error() string
- func (err *AppError) GetConflictData() interface{}
- func (err *AppError) GetDebug() error
- func (err *AppError) GetStatus() int
- func (err *AppError) IsBadRequest() bool
- func (err *AppError) IsForbidden() bool
- func (err *AppError) IsInternalError() bool
- func (err *AppError) IsInternalServerError() bool
- func (err *AppError) IsStatusNotFound() bool
- func (err *AppError) Log()
- func (err *AppError) MarshalJSON() ([]byte, error)
- func (err *AppError) NotNil() bool
- func (err *AppError) OverwriteStatusCode()
- func (err *AppError) UnmarshalJSON(b []byte) error
- func (err *AppError) UpdateMsg(msg string)
- func (err *AppError) UpdateStatus(statusCode int)
- func (err *AppError) WithNoLog() *AppError
- func (err *AppError) Wrap(cause error, message string) *AppError
- func (err *AppError) Wrapd(message string) *AppError
- func (err *AppError) Wrapf(cause error, format string, args ...interface{}) *AppError
- type Details
- type ErrorCode
Constants ¶
const MaxStackTraceLimit = 5
MaxStackTraceLimit allows to print only max 5 frames
Variables ¶
var ( NoActiveSubscription = ErrorCode{ // contains filtered or unexported fields } )
All the defined Internal ErrorCodes
Functions ¶
func Errorf ¶
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 ¶
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.
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 ¶
BadRequest will return `http.StatusBadRequest` with custom message.
func InternalServer ¶
InternalServer will return `http.StatusInternalServerError` with custom message.
func InternalServerStd ¶
func InternalServerStd() *AppError
InternalServerStd will return `http.StatusInternalServerError` with static message.
func InvalidKey ¶
InvalidKey returns new error with custom error message
func KeyRequired ¶
KeyRequired returns new error with custom error message
func NewAppError ¶
NewAppError returns the new apperror object
func PaymentRequired ¶
PaymentRequired will return `http.StatusPaymentRequired` with custom message.
func TooManyRequests ¶
TooManyRequests will return `http.StatusTooManyRequests` with custom message.
func Unauthorized ¶
Unauthorized will return `http.StatusUnauthorized` with custom message.
func UnprocessableEntity ¶
UnprocessableEntity will return `http.StatusUnprocessableEntity` with custom message.
func (*AppError) AddConflictData ¶
AddConflictData add extra conflict error information. This will be sent in meta
func (*AppError) AddDebug ¶
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 ¶
AddDebugf is a helper function which calls fmt.Errorf internally for the error which is added a Debug
func (*AppError) AddErrorDetail ¶
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 ¶
DebugError returns the detailed warped error message if present, else returns default msg.
func (*AppError) GetConflictData ¶
func (err *AppError) GetConflictData() interface{}
GetConflictData returns the conflict data if present
func (*AppError) GetDebug ¶
GetDebug returns the debug error if presents else returns new error of the message
func (*AppError) IsBadRequest ¶
IsBadRequest should return true if HTTP status of an error is 400.
func (*AppError) IsForbidden ¶
IsForbidden should return true if HTTP status of an error is 403.
func (*AppError) IsInternalError ¶
IsInternalError should return true if HTTP status of an error is >= 5XX.
func (*AppError) IsInternalServerError ¶
IsInternalServerError should return true if HTTP status of an error is 500.
func (*AppError) IsStatusNotFound ¶
IsStatusNotFound should return true if HTTP status of an error is 404.
func (*AppError) MarshalJSON ¶
MarshalJSON converts the AppError struct to JSON bytes
func (*AppError) OverwriteStatusCode ¶
func (err *AppError) OverwriteStatusCode()
OverwriteStatusCode change the status code to 460, if the error contains context canceled.
func (*AppError) UnmarshalJSON ¶
UnmarshalJSON convets a byte back to the AppError struct
func (*AppError) UpdateStatus ¶
UpdateStatus lets overrides the status code which is passed
func (*AppError) WithNoLog ¶
WithNoLog enables the no logging for this particular error. this can be invoked at the handler level return err.WithNoLog()
func (*AppError) Wrap ¶
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.