Files
descrybe/apps/api/internal/campaigns/errors.go
T
greeneclipse 8580c996c3 Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
2026-08-09 22:47:43 +02:00

53 lines
2.1 KiB
Go

package campaigns
import "errors"
var (
ErrNotFound = errors.New("campaign not found")
ErrProviderNotFound = errors.New("email provider not configured")
ErrProviderUnverified = errors.New("email provider not verified")
ErrInvalidEmail = errors.New("invalid email address")
ErrInvalidTemplate = errors.New("invalid template_key")
ErrInvalidStatus = errors.New("invalid status")
ErrMissingContent = errors.New("campaign has no generated content")
ErrAIRequiresUpgrade = errors.New("campaign AI generate requires a paid plan or AI credits")
ErrInsufficientCredits = errors.New("insufficient credits for campaign AI generate")
ErrAIUnavailable = errors.New("AI generation is not configured")
ErrRateLimited = errors.New("rate limit exceeded")
ErrUnsubscribed = errors.New("recipient is unsubscribed")
ErrMissingUnsubscribe = errors.New("generated HTML missing unsubscribe footer")
ErrPromptTooLong = errors.New("prompt exceeds maximum length")
ErrNameRequired = errors.New("name required")
ErrNoRecipients = errors.New("no recipients")
ErrConfirmRequired = errors.New("confirmation required to send campaign")
ErrTooManyProductIDs = errors.New("too many product_ids")
ErrTooManyCategoryIDs = errors.New("too many category_ids")
)
// ClientError reports whether err is a known client-facing campaign validation error.
func ClientError(err error) (msg string, ok bool) {
switch {
case err == nil:
return "", false
case errors.Is(err, ErrInvalidTemplate),
errors.Is(err, ErrInvalidStatus),
errors.Is(err, ErrInvalidEmail),
errors.Is(err, ErrMissingContent),
errors.Is(err, ErrMissingUnsubscribe),
errors.Is(err, ErrPromptTooLong),
errors.Is(err, ErrNameRequired),
errors.Is(err, ErrNoRecipients),
errors.Is(err, ErrAIUnavailable),
errors.Is(err, ErrConfirmRequired),
errors.Is(err, ErrTooManyProductIDs),
errors.Is(err, ErrTooManyCategoryIDs),
errors.Is(err, ErrUnsubscribed),
errors.Is(err, ErrRateLimited),
errors.Is(err, ErrProviderNotFound),
errors.Is(err, ErrProviderUnverified):
return err.Error(), true
default:
return "", false
}
}