Documentation
¶
Index ¶
- Variables
- func As(err error, target any) bool
- func Detail[T any](err error) (detail *T)
- func HttpStatus(err error) int
- func Is(err error, target error) bool
- func IsAborted(err error) bool
- func IsConflict(err error) bool
- func IsInternal(err error) bool
- func IsInvalidArgument(err error) bool
- func IsNotFound(err error) bool
- func IsNotImplemented(err error) bool
- func IsPreconditionFailed(err error) bool
- func IsStatus(err error) bool
- func IsUnauthenticated(err error) bool
- func IsUnauthorized(err error) bool
- func Join(errs ...error) error
- func Message(err error) string
- func New(text string) error
- func Source(err error) error
- func Unwrap(err error) error
- type Code
- type Status
- func Aborted(format string, args ...interface{}) *Status
- func AsStatus(err error) (e *Status)
- func Conflict(format string, args ...interface{}) *Status
- func Format(code Code, format string, args ...interface{}) *Status
- func Internal(format string, args ...interface{}) *Status
- func InvalidArgument(format string, args ...interface{}) *Status
- func NotFound(format string, args ...interface{}) *Status
- func NotImplemented(format string, args ...interface{}) *Status
- func PreconditionFailed(format string, args ...interface{}) *Status
- func Unauthenticated(format string, args ...interface{}) *Status
- func Unauthorized(format string, args ...interface{}) *Status
Constants ¶
This section is empty.
Variables ¶
var ( HttpMap = map[Code]int{ CodeConflict: http.StatusConflict, CodeInternal: http.StatusInternalServerError, CodeInvalidArgument: http.StatusBadRequest, CodeNotFound: http.StatusNotFound, CodeNotImplemented: http.StatusNotImplemented, CodeUnauthenticated: http.StatusUnauthorized, CodeUnauthorized: http.StatusForbidden, CodePreconditionFailed: http.StatusPreconditionFailed, CodeAborted: http.StatusInternalServerError, } )
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 IsInvalidArgument ¶
IsInvalidArgument checks if err is invalid argument error.
func IsNotImplemented ¶
IsNotImplemented checks if err is not implemented error.
func IsPreconditionFailed ¶
IsPreconditionFailed checks if err is precondition failed error.
func IsUnauthenticated ¶
IsUnauthenticated checks if err is unauthenticated error.
func IsUnauthorized ¶
IsUnauthorized checks if err is unauthorized error.
Types ¶
type Code ¶ added in v0.3.0
type Code string
const ( CodeConflict Code = "conflict" CodeInternal Code = "internal" CodeInvalidArgument Code = "invalid" CodeNotFound Code = "not_found" CodeNotImplemented Code = "not_implemented" CodeUnauthenticated Code = "unauthenticated" CodePreconditionFailed Code = "precondition_failed" CodeAborted Code = "aborted" )
type Status ¶
type Status struct {
// Source error
Err error `json:"source_error,omitempty"`
// Machine-readable status code.
Code Code `json:"code"`
// Human-readable error message.
Message string `json:"message"`
// Payload
Payload any `json:"detail,omitempty"`
}
func Format ¶
Format is a helper function to return an Error with a given status and formatted message.
func InvalidArgument ¶
InvalidArgument is a helper function to return an invalid argument Error.
func NotImplemented ¶
NotImplemented is a helper function to return an not found Error.
func PreconditionFailed ¶
PreconditionFailed is a helper function to return an precondition failed error.
func Unauthenticated ¶
Unauthenticated is a helper function to return unauthenticated error status.
func Unauthorized ¶
Unauthorized is a helper function to return unauthorized error status.