Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,13 @@ func Unauthorizedf(format string, args ...interface{}) error
Unauthorizedf returns an error which satisfies IsUnauthorized().


## func Forbiddenf
``` go
func Forbiddenf(format string, args ...interface{}) error
```
Forbiddenf returns an error which satisfies IsForbidden().


## func Wrap
``` go
func Wrap(other, newDescriptive error) error
Expand Down
25 changes: 25 additions & 0 deletions errortypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,28 @@ func IsMethodNotAllowed(err error) bool {
_, ok := err.(*methodNotAllowed)
return ok
}

// forbidden represents an error when a request cannot be completed because of
// missing privileges
type forbidden struct {
Err
}

// Forbiddenf returns an error which satistifes IsForbidden()
func Forbiddenf(format string, args ...interface{}) error {
return &forbidden{wrap(nil, format, "", args...)}
}

// NewForbidden returns an error which wraps err that satisfies
// IsForbidden().
func NewForbidden(err error, msg string) error {
return &forbidden{wrap(err, msg, "")}
}

// IsForbidden reports whether err was created with Forbiddenf() or
// NewForbidden().
func IsForbidden(err error) bool {
err = Cause(err)
_, ok := err.(*forbidden)
return ok
}
1 change: 1 addition & 0 deletions errortypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var allErrors = []*errorInfo{
&errorInfo{errors.IsNotAssigned, errors.NotAssignedf, errors.NewNotAssigned, " not assigned"},
&errorInfo{errors.IsMethodNotAllowed, errors.MethodNotAllowedf, errors.NewMethodNotAllowed, ""},
&errorInfo{errors.IsBadRequest, errors.BadRequestf, errors.NewBadRequest, ""},
&errorInfo{errors.IsForbidden, errors.Forbiddenf, errors.NewForbidden, ""},
}

type errorTypeSuite struct{}
Expand Down