Files
descrybe/apps/api/internal/billing/client_errors.go
T

37 lines
1.1 KiB
Go
Raw Normal View History

package billing
import "errors"
var (
ErrPlanNameRequired = errors.New("name required")
ErrPlanNotFound = errors.New("plan not found")
ErrAmountRequired = errors.New("amount required")
ErrStripeNoCustomer = errors.New("no stripe customer for this company — complete a checkout first")
)
// ClientError reports whether err is a known client-facing billing/Stripe error.
func ClientError(err error) (msg string, ok bool) {
switch {
case err == nil:
return "", false
case errors.Is(err, ErrPlanNameRequired),
errors.Is(err, ErrPlanNotFound),
errors.Is(err, ErrAmountRequired),
errors.Is(err, ErrStripeNotConfigured),
errors.Is(err, ErrStripePlanUnsupported),
errors.Is(err, ErrStripePriceMissing),
errors.Is(err, ErrStripeNoCustomer),
errors.Is(err, ErrInsufficientCredits),
errors.Is(err, ErrProductLimitExceeded),
errors.Is(err, ErrAIRequiresUpgrade),
errors.Is(err, ErrEPRELRequiresUpgrade),
errors.Is(err, ErrUnknownFeatureKey),
errors.Is(err, ErrUnknownFeatureSection),
errors.Is(err, ErrInvalidFeatureGates),
errors.Is(err, ErrFeatureDisabled):
return err.Error(), true
default:
return "", false
}
}