feat(xerrors)!: promote to v1.0.0 — add Unauthorized and PermissionDenied constructors
Add Unauthorized and PermissionDenied convenience constructors to complete the set of the five most-used error codes (InvalidInput, NotFound, Internal, Unauthorized, PermissionDenied). All roadmap items from v0.9.0 resolved. API committed as stable.
This commit is contained in:
12
xerrors.go
12
xerrors.go
@@ -67,6 +67,18 @@ func Internal(msg string, args ...any) *Err {
|
||||
return New(ErrInternal, fmt.Sprintf(msg, args...))
|
||||
}
|
||||
|
||||
// Unauthorized creates an Err with [ErrUnauthorized] code.
|
||||
// msg is formatted with args using [fmt.Sprintf] rules.
|
||||
func Unauthorized(msg string, args ...any) *Err {
|
||||
return New(ErrUnauthorized, fmt.Sprintf(msg, args...))
|
||||
}
|
||||
|
||||
// PermissionDenied creates an Err with [ErrPermissionDenied] code.
|
||||
// msg is formatted with args using [fmt.Sprintf] rules.
|
||||
func PermissionDenied(msg string, args ...any) *Err {
|
||||
return New(ErrPermissionDenied, fmt.Sprintf(msg, args...))
|
||||
}
|
||||
|
||||
// WithContext adds a key-value pair to the error's context fields and returns
|
||||
// the receiver for chaining. Calling it multiple times with the same key
|
||||
// overwrites the previous value.
|
||||
|
||||
Reference in New Issue
Block a user