Documentation ¶
Index ¶
- Constants
- Variables
- func As(err error, target any) bool
- func Code(err error) string
- func Is(err, target error) bool
- func Message(err error) string
- func New(message string) error
- func Unwrap(err error) error
- type Error
- func ErrorF(err error, op, format string, args ...any) *Error
- func NewConflict(err error, message, op string) *Error
- func NewE(err error, message, op string) *Error
- func NewExpired(err error, message, op string) *Error
- func NewInternal(err error, message, op string) *Error
- func NewInvalid(err error, message, op string) *Error
- func NewMaximumAttempts(err error, message, op string) *Error
- func NewNotFound(err error, message, op string) *Error
- func NewUnknown(err error, message, op string) *Error
- func ToError(err any) *Error
- func Wrap(err error, message string) *Error
- func (e *Error) Error() string
- func (e *Error) FileLine() string
- func (e *Error) HTTPStatusCode() int
- func (e *Error) MarshalJSON() ([]byte, error)
- func (e *Error) ProgramCounters() []uintptr
- func (e *Error) RuntimeFrames() *runtime.Frames
- func (e *Error) Scan(value any) error
- func (e *Error) StackTrace() string
- func (e *Error) StackTraceSlice() []string
- func (e *Error) UnmarshalJSON(data []byte) error
- func (e *Error) Unwrap() error
- func (e *Error) Value() (driver.Value, error)
Constants ¶
const ( // CONFLICT - An action cannot be performed. CONFLICT = "conflict" // INTERNAL - Error within the application. INTERNAL = "internal" // INVALID - Validation failed. INVALID = "invalid" // NOTFOUND - Entity does not exist. NOTFOUND = "not_found" // UNKNOWN - Application unknown error. UNKNOWN = "unknown" // MAXIMUMATTEMPTS - More than allowed action. MAXIMUMATTEMPTS = "maximum_attempts" // EXPIRED - Subscription expired. EXPIRED = "expired" )
Application error codes.
Variables ¶
var ( // DefaultCode is the default code returned when // none is specified. DefaultCode = INTERNAL // GlobalError is a general message when no error message // has been found. GlobalError = "An error has occurred." )
Functions ¶
Types ¶
type Error ¶
type Error struct { // The application error code. Code string `json:"code" bson:"code"` // A human-readable message to send back to the end user. Message string `json:"message" bson:"message"` // Defines what operation is currently being run. Operation string `json:"operation" bson:"op"` // The error that was returned from the caller. Err error `json:"error" bson:"error"` // contains filtered or unexported fields }
Error defines a standard application error.
func NewConflict ¶
NewConflict returns an Error with a CONFLICT error code.
func NewExpired ¶
NewExpired returns an Error with a EXPIRED error code.
func NewInternal ¶
NewInternal returns an Error with a INTERNAL error code.
func NewInvalid ¶
NewInvalid returns an Error with a INVALID error code.
func NewMaximumAttempts ¶
NewMaximumAttempts returns an Error with a MAXIMUMATTEMPTS error code.
func NewNotFound ¶
NewNotFound returns an Error with a NOTFOUND error code.
func NewUnknown ¶
NewUnknown returns an Error with a UNKNOWN error code.
func ToError ¶
ToError Returns an application error from input. If The type is not of type Error, nil will be returned.
func 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 (*Error) Error ¶
Error returns the string representation of the error message by implementing the error interface.
func (*Error) HTTPStatusCode ¶
HTTPStatusCode is a convenience method used to get the appropriate HTTP response status code for the respective error type.
func (*Error) MarshalJSON ¶ added in v0.0.2
MarshalJSON implements encoding/Marshaller to wrap the error as a string if there is one.
func (*Error) ProgramCounters ¶
ProgramCounters returns the slice of PC values associated with the error.
func (*Error) RuntimeFrames ¶
RuntimeFrames returns function/file/line information.
func (*Error) StackTrace ¶
StackTrace returns a string representation of the errors stacktrace, where each trace is separated by a newline and tab '\t'.
func (*Error) StackTraceSlice ¶
StackTraceSlice returns a string slice of the errors stacktrace.
func (*Error) UnmarshalJSON ¶ added in v0.0.2
UnmarshalJSON implements encoding/Marshaller to unmarshal the wrapping error to type Error.