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
24 changes: 24 additions & 0 deletions errortypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,27 @@ func IsForbidden(err error) bool {
_, ok := err.(*forbidden)
return ok
}

// quotaLimitExceeded is emitted when an action failed due to a quota limit check.
type quotaLimitExceeded struct {
Err
}

// QuotaLimitExceededf returns an error which satisfies IsQuotaLimitExceeded.
func QuotaLimitExceededf(format string, args ...interface{}) error {
return &quotaLimitExceeded{wrap(nil, format, "", args...)}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I noticed that Err itself is returned as a struct, not as a *struct. Given that quotaLimitExceeded is-a Err, shouldn't we just return quotaLimitExceeded here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. There is really no point in returning pointers here (or using pointer receivers for Error for that matter). I just emulated (a.k.a copy/paste/modify) the behavior from the other error types in the same file.

}

// NewQuotaLimitExceeded returns an error which wraps err and satisfies
// IsQuotaLimitExceeded.
func NewQuotaLimitExceeded(err error, msg string) error {
return &quotaLimitExceeded{wrap(err, msg, "")}
}

// IsQuotaLimitExceeded returns true if the given error represents a
// QuotaLimitExceeded error.
func IsQuotaLimitExceeded(err error) bool {
err = Cause(err)
_, ok := err.(*quotaLimitExceeded)
return ok
}
1 change: 1 addition & 0 deletions errortypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var allErrors = []*errorInfo{
{errors.IsMethodNotAllowed, errors.MethodNotAllowedf, errors.NewMethodNotAllowed, ""},
{errors.IsBadRequest, errors.BadRequestf, errors.NewBadRequest, ""},
{errors.IsForbidden, errors.Forbiddenf, errors.NewForbidden, ""},
{errors.IsQuotaLimitExceeded, errors.QuotaLimitExceededf, errors.NewQuotaLimitExceeded, ""},
}

type errorTypeSuite struct{}
Expand Down