Skip to content
This repository has been archived by the owner on Aug 27, 2020. It is now read-only.

Commit

Permalink
Exported ErrAdjustBounds and ErrAdjustInvalid errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hassieswift621 committed Dec 3, 2019
1 parent 12ca42a commit 631b602
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
15 changes: 7 additions & 8 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import (
"golang.org/x/xerrors"
)

// ErrAdjustBounds is returned by the adjust guild points and score methods if the amount to adjust is invalid.
var ErrAdjustBounds = xerrors.New("tatsumakigo: the amount to adjust must be between 0 and 50,000 (inclusive)")

// ErrAdjustInvalid is returned by the adjust guild points and score methods if the amount to adjust
// for an action is invalid.
var ErrAdjustInvalid = xerrors.New("tatsumakigo: the amount to adjust for add and remove actions must be above 0")

func errorRequestFailed(err error) error {
return xerrors.Errorf("tatsumakigo: failed to create request: %w", err)
}
Expand All @@ -19,11 +26,3 @@ func errorResponseFailed(err error) error {
func errorParseFailed(err error) error {
return xerrors.Errorf("tatsumakigo: failed to parse response: %w", err)
}

func errorAdjustInvalid() error {
return xerrors.New("tatsumakigo: the amount to adjust for add and remove actions must be above 0")
}

func errorAdjustBounds() error {
return xerrors.New("tatsumakigo: the amount to adjust must be between 0 and 50,000 (inclusive)")
}
8 changes: 4 additions & 4 deletions rest_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func (rc *restClient) adjustGuildUserPoints(ctx context.Context, guildID string,
action Action) (*GuildUserPoints, error) {
// Check if amount is 0 and action is add or remove.
if amount == 0 && (action == ActionAdd || action == ActionRemove) {
return nil, errorAdjustInvalid()
return nil, ErrAdjustInvalid
}

// Check if amount is between 0 and 50,000 (inclusive).
if amount < 0 || amount > 50000 {
return nil, errorAdjustBounds()
return nil, ErrAdjustBounds
}

// Make request.
Expand All @@ -63,12 +63,12 @@ func (rc *restClient) adjustGuildUserScore(ctx context.Context, guildID string,
action Action) (*GuildUserScore, error) {
// Check if amount is 0 and action is add or remove.
if amount == 0 && (action == ActionAdd || action == ActionRemove) {
return nil, errorAdjustInvalid()
return nil, ErrAdjustInvalid
}

// Check if amount is between 0 and 50,000 (inclusive).
if amount < 0 || amount > 50000 {
return nil, errorAdjustBounds()
return nil, ErrAdjustBounds
}

// Make request.
Expand Down

0 comments on commit 631b602

Please sign in to comment.