53 lines
2.1 KiB
Go
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
|
||
|
|
}
|
||
|
|
}
|