Documentation
¶
Index ¶
- Variables
- func As(err error, target interface{}) bool
- func Code(err error) int
- func Is(err, target error) bool
- func Reason(err error) string
- func Unwrap(err error) error
- type ErrorX
- func (e *ErrorX) Error() string
- func (e *ErrorX) GRPCStatus() *status.Status
- func (err *ErrorX) Is(target error) bool
- func (e *ErrorX) KV(kvs ...string) *ErrorX
- func (e *ErrorX) WithMessage(format string, args ...any) *ErrorX
- func (e *ErrorX) WithMetaData(md map[string]string) *ErrorX
- func (e *ErrorX) WithRequestID(requestID string) *ErrorX
Constants ¶
This section is empty.
Variables ¶
var ( OK = &ErrorX{Code: http.StatusOK, Msg: ""} ErrInternal = &ErrorX{Code: http.StatusInternalServerError, Reason: "InternalError", Msg: "Internal server error."} ErrNotFound = &ErrorX{Code: http.StatusNotFound, Reason: "NotFound", Msg: "NotFound."} ErrBind = &ErrorX{Code: http.StatusBadRequest, Reason: "BindError", Msg: "Error occurred while binding the request body to the struct."} ErrInvalidArgument = &ErrorX{Code: http.StatusBadRequest, Reason: "InvalidArgument", Msg: "InvalidArgument."} ErrUnauthenticated = &ErrorX{Code: http.StatusUnauthorized, Reason: "Unauthenticated", Msg: "Unauthenticated."} ErrPermissionDenied = &ErrorX{Code: http.StatusForbidden, Reason: "PermissionDenied", Msg: "Permission denied."} ErrOperationFailed = &ErrorX{Code: http.StatusConflict, Reason: "OperationFailed", Msg: "OperationFailed."} )
define error codes for the application
Functions ¶
func As ¶
As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true.
The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.
An error matches target if the error's concrete value is assignable to the value pointed to by target, or if the error has a method As(interface{}) bool such that As(target) returns true. In the latter case, the As method is responsible for setting target.
As will panic if target is not a non-nil pointer to either a type that implements error, or to any interface type. As returns false if err is nil.
func Is ¶
Is reports whether any error in err's chain matches target.
The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.
An error is considered to match a target if it is equal to that target or if it implements a method Is(error) bool such that Is(target) returns true.
Types ¶
type ErrorX ¶
type ErrorX struct {
Code int `json:"code,omitempty"`
Msg string `json:"msg,omitempty"`
Reason string `json:"reason,omitempty"`
MetaData map[string]string `json:"meta_data,omitempty"`
}
ErrorX defines a standardized error structure for API responses