From cea9328be951c25c1230273082b4a383562e171d Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Wed, 12 Jun 2024 17:45:32 +0100 Subject: [PATCH] new errors --- internal/executor/add.go | 4 ++-- internal/executor/errors.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/executor/add.go b/internal/executor/add.go index 3c85cb3..9955017 100644 --- a/internal/executor/add.go +++ b/internal/executor/add.go @@ -265,11 +265,11 @@ func (a *AddExecutor) addVoteToPoll(gtsClient *client.Client) error { } if poll.Expired { - return errors.New("this poll has expired") + return ExpiredPollError{} } if !poll.Multiple && len(a.choices) > 1 { - return errors.New("this poll does not allow multiple choices") + return MultipleChoiceError{} } if err := gtsClient.VoteInPoll(a.pollID, []int(a.choices)); err != nil { diff --git a/internal/executor/errors.go b/internal/executor/errors.go index c7dd944..9fa9fef 100644 --- a/internal/executor/errors.go +++ b/internal/executor/errors.go @@ -66,3 +66,15 @@ type UnknownCommandError struct { func (e UnknownCommandError) Error() string { return "unknown command '" + e.Command + "'" } + +type ExpiredPollError struct{} + +func (e ExpiredPollError) Error() string { + return "this poll has expired" +} + +type MultipleChoiceError struct{} + +func (e MultipleChoiceError) Error() string { + return "this poll does not allow multiple choices" +}