Documentation
¶
Index ¶
- func As(err error, target any) bool
- func Details(err error) error
- 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 Response(encoder Encoder, w http.ResponseWriter, err error)
- func TraceID(id string, t error) error
- func Unwrap(err error) error
- type Base
- type ConflictError
- type Encoder
- type Errors
- type HttpResponse
- type InternalError
- type JSONResponseFunc
- type JSONResponseOption
- type NotFoundError
- type NotImplementedError
- type PreconditionFailedError
- type UnauthenticatedError
- type UnauthorizedError
- type ValidationError
- func (e *ValidationError) AddError(err error) *ValidationError
- func (e *ValidationError) AsError() error
- func (e *ValidationError) Check(ok bool, err error)
- func (e *ValidationError) Error() string
- func (e *ValidationError) ErrorDetails() string
- func (e *ValidationError) HttpResponse() HttpResponse
- func (e *ValidationError) Is(err error) bool
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 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"`
StatusCode string `json:"status,omitempty"`
TraceID string `json:"trace_id,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
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 Errors `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) ErrorDetails ¶ added in v0.6.0
func (e *ConflictError) ErrorDetails() string
func (*ConflictError) HttpResponse ¶ added in v0.4.0
func (e *ConflictError) HttpResponse() HttpResponse
HttpResponse returns http response for ConflictError.
func (*ConflictError) Is ¶ added in v0.3.1
func (e *ConflictError) Is(err error) bool
Is checks if err is ConflictError.
type HttpResponse ¶ added in v0.4.0
func (*HttpResponse) AsError ¶ added in v0.6.0
func (r *HttpResponse) AsError() error
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)
AsInternal return err as InternalError or nil if it is not successfull.
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) ErrorDetails ¶ added in v0.6.0
func (e *InternalError) ErrorDetails() string
func (*InternalError) HttpResponse ¶ added in v0.4.0
func (e *InternalError) HttpResponse() HttpResponse
HttpResponse returns http response for InternalError.
func (*InternalError) Is ¶ added in v0.6.0
func (e *InternalError) Is(err error) bool
type JSONResponseFunc ¶ added in v0.3.1
type JSONResponseFunc func(*Base)
func ProcessStatus ¶ added in v0.3.1
func ProcessStatus(fn func(status string) 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 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) ErrorDetails ¶ added in v0.6.0
func (e *NotFoundError) ErrorDetails() string
func (*NotFoundError) HttpResponse ¶ added in v0.4.0
func (e *NotFoundError) HttpResponse() HttpResponse
HttpResponse returns http response 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 AsNotImplemented ¶ added in v0.6.0
func AsNotImplemented(err error) (nerr *NotImplementedError, b bool)
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) ErrorDetails ¶ added in v0.6.0
func (e *NotImplementedError) ErrorDetails() string
func (*NotImplementedError) HttpResponse ¶ added in v0.4.0
func (e *NotImplementedError) HttpResponse() HttpResponse
HttpResponse returns http response for NotImplementedError.
func (*NotImplementedError) Is ¶ added in v0.6.0
func (e *NotImplementedError) Is(err error) bool
type PreconditionFailedError ¶ added in v0.3.1
func AsPreconditionFailed ¶ added in v0.6.0
func AsPreconditionFailed(err error) (perr *PreconditionFailedError, b bool)
func PreconditionFailed ¶
func PreconditionFailed(format string, args ...any) *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) ErrorDetails ¶ added in v0.6.0
func (e *PreconditionFailedError) ErrorDetails() string
func (*PreconditionFailedError) HttpResponse ¶ added in v0.4.0
func (e *PreconditionFailedError) HttpResponse() HttpResponse
HttpResponse returns http response for PreconditionFailedError.
func (*PreconditionFailedError) Is ¶ added in v0.6.0
func (e *PreconditionFailedError) Is(err error) bool
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) ErrorDetails ¶ added in v0.6.0
func (e *UnauthenticatedError) ErrorDetails() string
func (*UnauthenticatedError) HttpResponse ¶ added in v0.4.0
func (e *UnauthenticatedError) HttpResponse() HttpResponse
HttpResponse returns http response for UnauthenticatedError.
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) ErrorDetails ¶ added in v0.6.0
func (e *UnauthorizedError) ErrorDetails() string
func (*UnauthorizedError) HttpResponse ¶ added in v0.4.0
func (e *UnauthorizedError) HttpResponse() HttpResponse
HttpResponse returns http response for UnauthorizedError.
type ValidationError ¶ added in v0.3.1
func AsUnautenticated ¶ added in v0.6.0
func AsUnautenticated(err error) (verr *ValidationError, b bool)
func AsUnauthorized ¶ added in v0.6.0
func AsUnauthorized(err error) (verr *ValidationError, b bool)
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) AsError ¶ added in v0.6.0
func (e *ValidationError) AsError() error
func (*ValidationError) Check ¶ added in v0.6.0
func (e *ValidationError) Check(ok bool, err error)
func (*ValidationError) Error ¶ added in v0.3.1
func (e *ValidationError) Error() string
func (*ValidationError) ErrorDetails ¶ added in v0.6.0
func (e *ValidationError) ErrorDetails() string
func (*ValidationError) HttpResponse ¶ added in v0.4.0
func (e *ValidationError) HttpResponse() HttpResponse
HttpResponse returns http response for ValidationError.
func (*ValidationError) Is ¶ added in v0.3.1
func (e *ValidationError) Is(err error) bool