Documentation ¶
Index ¶
- func As(err error, target any) bool
- func HttpStatus(err error) int
- func Is(err error, target error) bool
- func IsConflict(err error) bool
- func IsInternal(err error) bool
- func IsNotFound(err error) bool
- func IsNotImplemented(err error) bool
- func IsPreconditionFailed(err error) bool
- func IsUnauthenticated(err error) bool
- func IsUnauthorized(err error) bool
- func IsValidation(err error) bool
- func JSONResponse(w http.ResponseWriter, err error, options ...JSONResponseOption) error
- func Join(errs ...error) error
- func New(text string) error
- func TraceID(id string, t error) error
- func Unwrap(err error) error
- type Base
- type ConflictError
- type InternalError
- type JSONResponseFunc
- type JSONResponseOption
- type MarshalableErrors
- type NotFoundError
- type NotImplementedError
- type PreconditionFailedError
- type UnauthenticatedError
- type UnauthorizedError
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶
As finds the first error in err's tree that matches target, and if one is found, sets target to that error value and returns true. Otherwise, it returns false.
func HttpStatus ¶
func IsNotImplemented ¶
IsNotImplemented checks if err is not implemented error.
func IsPreconditionFailed ¶
IsInternal checks if err is internal error.
func IsUnauthenticated ¶
func IsUnauthorized ¶
func IsValidation ¶ added in v0.3.1
IsValidation checks if err is invalid argument error.
func JSONResponse ¶ added in v0.3.1
func JSONResponse(w http.ResponseWriter, err error, options ...JSONResponseOption) error
Types ¶
type Base ¶ added in v0.3.1
type Base struct { // Msg contains user friendly error. Msg string `json:"message"` Status int `json:"status,omitempty"` TraceID string `json:"trace_id,omitempty"` Timestamp time.Time `json:"timestamp,omitempty"` }
func (*Base) SetTraceID ¶ added in v0.3.1
type ConflictError ¶ added in v0.3.1
type ConflictError struct { Base // Item is a conflicting resource. Item any `json:"item,omitempty"` Errors MarshalableErrors `json:"errors"` }
ConflictError holds fields for conflict error.
func AsConflict ¶ added in v0.3.1
func AsConflict(err error) (cerr *ConflictError, b bool)
AsConflict return err as ConflictError or nil if it is not successfull.
func Conflict ¶
func Conflict(format string, args ...any) *ConflictError
Conflict is a helper function to return an ConflictError. In format argument Item can be specified with ${} specifier for example:
- errors.Conflict("article ${123} already exist")
- errors.Conflict("article ${%d} already exist", 123)
- errors.Conflict("group %s and article ${%d} already exist", 1, 123)
the value of Item in ConflictError will be set to 123.
func (*ConflictError) AddError ¶ added in v0.3.1
func (e *ConflictError) AddError(err error) *ConflictError
func (*ConflictError) Error ¶ added in v0.3.1
func (e *ConflictError) Error() string
Error interface method.
func (*ConflictError) HttpStatus ¶ added in v0.3.1
func (e *ConflictError) HttpStatus() int
HttpStatus returns http status for ConflictError.
func (*ConflictError) Is ¶ added in v0.3.1
func (e *ConflictError) Is(t error) bool
Is checks if err is ConflictError.
type InternalError ¶ added in v0.3.1
type InternalError struct { Base Err error `json:"-"` Stacktrace json.RawMessage `json:"-"` }
func AsInternal ¶ added in v0.3.1
func AsInternal(err error) (ierr *InternalError, b bool)
func Internal ¶
func Internal(err error, format string, args ...any) *InternalError
Internal is a helper function to return an internal Error.
func (*InternalError) Error ¶ added in v0.3.1
func (e *InternalError) Error() string
func (*InternalError) HttpStatus ¶ added in v0.3.1
func (e *InternalError) HttpStatus() int
type JSONResponseFunc ¶ added in v0.3.1
type JSONResponseFunc func(*Base)
func ProcessStatus ¶ added in v0.3.1
func ProcessStatus(fn func(status int) error) JSONResponseFunc
func WithTraceID ¶ added in v0.3.1
func WithTraceID(traceID string) JSONResponseFunc
func (JSONResponseFunc) Apply ¶ added in v0.3.1
func (f JSONResponseFunc) Apply(b *Base)
type JSONResponseOption ¶ added in v0.3.1
type JSONResponseOption interface {
Apply(*Base)
}
type MarshalableErrors ¶ added in v0.3.1
type MarshalableErrors []error
func (MarshalableErrors) MarshalJSON ¶ added in v0.3.1
func (me MarshalableErrors) MarshalJSON() ([]byte, error)
type NotFoundError ¶ added in v0.3.1
func AsNotFound ¶ added in v0.3.1
func AsNotFound(err error) (nerr *NotFoundError, b bool)
AsNotFound return err as NotFoundError or nil if it is not successfull.
func NotFound ¶
func NotFound(format string, args ...any) *NotFoundError
NotFound is a helper function to return an NotFoundError. In format argument Item can be specified with ${} specifier for example:
- errors.NotFound("article ${123} already exist")
- errors.NotFound("article ${%d} already exist", 123)
- errors.NotFound("group %s and article ${%d} already exist", 1, 123)
the value of Item in NotFoundError will be set to 123.
func (*NotFoundError) Error ¶ added in v0.3.1
func (e *NotFoundError) Error() string
Error interface method.
func (*NotFoundError) HttpStatus ¶ added in v0.3.1
func (e *NotFoundError) HttpStatus() int
Is returns http status for NotFoundError
func (*NotFoundError) Is ¶ added in v0.3.1
func (e *NotFoundError) Is(err error) bool
type NotImplementedError ¶ added in v0.3.1
type NotImplementedError struct {
Base
}
func NotImplemented ¶
func NotImplemented(format string, args ...any) *NotImplementedError
InvalidArgument is a helper function to return an invalid argument Error.
func (*NotImplementedError) Error ¶ added in v0.3.1
func (e *NotImplementedError) Error() string
func (*NotImplementedError) HttpStatus ¶ added in v0.3.1
func (e *NotImplementedError) HttpStatus() int
type PreconditionFailedError ¶ added in v0.3.1
func PreconditionFailed ¶
func PreconditionFailed(format string, args ...interface{}) *PreconditionFailedError
Internal is a helper function to return an internal Error.
func (*PreconditionFailedError) Error ¶ added in v0.3.1
func (e *PreconditionFailedError) Error() string
func (*PreconditionFailedError) HttpStatus ¶ added in v0.3.1
func (e *PreconditionFailedError) HttpStatus() int
func (*PreconditionFailedError) SetErr ¶ added in v0.3.1
func (e *PreconditionFailedError) SetErr(err error) *PreconditionFailedError
type UnauthenticatedError ¶ added in v0.3.1
type UnauthenticatedError struct {
Base
}
func Unauthenticated ¶
func Unauthenticated(format string, args ...any) *UnauthenticatedError
func (*UnauthenticatedError) Error ¶ added in v0.3.1
func (e *UnauthenticatedError) Error() string
func (*UnauthenticatedError) HttpStatus ¶ added in v0.3.1
func (e *UnauthenticatedError) HttpStatus() int
type UnauthorizedError ¶ added in v0.3.1
type UnauthorizedError struct {
}func Unauthorized ¶
func Unauthorized(format string, args ...any) *UnauthorizedError
func (*UnauthorizedError) Error ¶ added in v0.3.1
func (e *UnauthorizedError) Error() string
func (*UnauthorizedError) HttpStatus ¶ added in v0.3.1
func (e *UnauthorizedError) HttpStatus() int
type ValidationError ¶ added in v0.3.1
type ValidationError struct { Base Errors MarshalableErrors `json:"errors,omitempty"` }
func AsValidation ¶ added in v0.3.1
func AsValidation(err error) (verr *ValidationError, b bool)
func Validation ¶ added in v0.3.1
func Validation(format string, args ...any) *ValidationError
Validation is a helper function to return an invalid argument Error.
func (*ValidationError) AddError ¶ added in v0.3.1
func (e *ValidationError) AddError(err error) *ValidationError
func (*ValidationError) Error ¶ added in v0.3.1
func (e *ValidationError) Error() string
func (*ValidationError) HttpStatus ¶ added in v0.3.1
func (e *ValidationError) HttpStatus() int
func (*ValidationError) Is ¶ added in v0.3.1
func (e *ValidationError) Is(err error) bool