Use status-specific errors for non-draft campaigns
Replace ErrCampaignCannotStart and ErrCampaignCannotUpdate with sentinels per campaign status, mapped through CampaignStatusError and wrapped with operation-specific fmt.Errorf prefixes. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
This commit is contained in:
@@ -20,10 +20,31 @@
|
||||
|
||||
package accessreview
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"go.probo.inc/probo/pkg/coredata"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrCampaignMissingSources = errors.New("cannot start campaign: no scope sources configured")
|
||||
ErrCampaignCannotStart = errors.New("cannot start campaign: only draft campaigns can be started")
|
||||
ErrCampaignCannotUpdate = errors.New("cannot update campaign: only draft campaigns can be updated")
|
||||
ErrCampaignInProgress = errors.New("campaign is in progress")
|
||||
ErrCampaignPendingActions = errors.New("campaign is pending actions")
|
||||
ErrCampaignCompleted = errors.New("campaign is completed")
|
||||
ErrCampaignCancelled = errors.New("campaign is cancelled")
|
||||
)
|
||||
|
||||
func CampaignStatusError(status coredata.AccessReviewCampaignStatus) error {
|
||||
switch status {
|
||||
case coredata.AccessReviewCampaignStatusInProgress:
|
||||
return ErrCampaignInProgress
|
||||
case coredata.AccessReviewCampaignStatusPendingActions:
|
||||
return ErrCampaignPendingActions
|
||||
case coredata.AccessReviewCampaignStatusCompleted:
|
||||
return ErrCampaignCompleted
|
||||
case coredata.AccessReviewCampaignStatusCancelled:
|
||||
return ErrCampaignCancelled
|
||||
default:
|
||||
return ErrCampaignInProgress
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user