Documentation ¶
Index ¶
- Variables
- func As(err error, target any) bool
- func Is(err, target error) bool
- type Error
- func AsLakeErrorType(err error) Error
- func Convert(err error) Error
- func Convert00001[T1 any, T2 any, T3 any, T4 any](t1 T1, t2 T2, t3 T3, t4 T4, err error) (T1, T2, T3, T4, Error)
- func Convert0001[T1 any, T2 any, T3 any](t1 T1, t2 T2, t3 T3, err error) (T1, T2, T3, Error)
- func Convert001[T1 any, T2 any](t1 T1, t2 T2, err error) (T1, T2, Error)
- func Convert01[T1 any](t1 T1, err error) (T1, Error)
- type MessageType
- type Messages
- type Option
- type Options
- type Type
Constants ¶
This section is empty.
Variables ¶
var ( // Default special error type. If it's wrapping another error, then it will take the type of that error if it's an Error. Otherwise, it equates to Internal. Default = register(nil) SubtaskErr = register(&Type{meta: "subtask"}) //400+ BadInput = register(&Type{httpCode: http.StatusBadRequest, meta: "bad-input"}) Forbidden = register(&Type{httpCode: http.StatusForbidden, meta: "forbidden"}) NotFound = register(&Type{httpCode: http.StatusNotFound, meta: "not-found"}) Conflict = register(&Type{httpCode: http.StatusConflict, meta: "internal"}) //500+ Internal = register(&Type{httpCode: http.StatusInternalServerError, meta: "internal"}) Timeout = register(&Type{httpCode: http.StatusGatewayTimeout, meta: "timeout"}) )
Supported error types
Functions ¶
Types ¶
type Error ¶
type Error interface { // Messages the message associated with this Error. Messages() Messages // GetType gets the Type of this error GetType() *Type // As Attempts to cast this Error to the requested Type, and returns nil if it can't. As(*Type) Error // GetData returns the data associated with this Error (may be nil) GetData() interface{} // contains filtered or unexported methods }
Error The interface that all internally managed errors should adhere to.
func AsLakeErrorType ¶
AsLakeErrorType attempts to cast err to Error, otherwise returns nil
func Convert ¶
Convert converts a raw error to an Error. Similar to Type.WrapRaw with a type of Default, but will not wrap the error if it's already of type Error. Passing in nil will return nil.
func Convert00001 ¶
func Convert00001[T1 any, T2 any, T3 any, T4 any](t1 T1, t2 T2, t3 T3, t4 T4, err error) (T1, T2, T3, T4, Error)
Convert00001 like Convert01, but with four extra args
func Convert0001 ¶
Convert0001 like Convert01, but with three extra args
func Convert001 ¶
Convert001 like Convert01, but with two extra args
type Messages ¶
type Messages []*errMessage
Messages alias for messages of an Error
type Type ¶
type Type struct {
// contains filtered or unexported fields
}
Type error are constructed from these, and they contain metadata about them.
func HttpStatus ¶
func (*Type) Combine ¶
Combine constructs a new Error from combining multiple errors. Stacktrace info for each of the errors will not be present in the result, so it's best to log the errors before combining them.
func (*Type) GetHttpCode ¶
GetHttpCode gets the associated Http code with this Type, if explicitly set, otherwise http.StatusInternalServerError
func (*Type) Wrap ¶
Wrap constructs a new Error instance with this message and wraps the passed in error. A nil 'err' will return a nil Error.