52 lines
1.7 KiB
Go
52 lines
1.7 KiB
Go
package textgen
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"git.threesix.ai/jordan/persona-community-3/pkg/routing"
|
|
)
|
|
|
|
// Domain errors for programmatic error handling with errors.Is().
|
|
//
|
|
// IMPORTANT: Core routing errors (ErrRateLimit, ErrQuotaExceeded, ErrServerUnavailable)
|
|
// are defined in pkg/routing. Provider implementations should wrap those errors.
|
|
var (
|
|
// ErrInvalidConfig indicates invalid manager or provider configuration.
|
|
ErrInvalidConfig = errors.New("textgen: invalid configuration")
|
|
|
|
// ErrInvalidRequest indicates an invalid generation request.
|
|
ErrInvalidRequest = errors.New("textgen: invalid request")
|
|
|
|
// ErrNoProvidersConfigured indicates no providers were configured.
|
|
ErrNoProvidersConfigured = errors.New("textgen: no providers configured")
|
|
|
|
// ErrAllProvidersFailed indicates all providers failed to generate.
|
|
// This is an alias for routing.ErrAllProvidersFailed.
|
|
ErrAllProvidersFailed = routing.ErrAllProvidersFailed
|
|
|
|
// ErrQuotaExceeded indicates the provider's quota has been exceeded.
|
|
// Re-exported from routing for convenience.
|
|
ErrQuotaExceeded = routing.ErrQuotaExceeded
|
|
|
|
// ErrRateLimited indicates the request was rate limited.
|
|
// Re-exported from routing for convenience.
|
|
ErrRateLimited = routing.ErrRateLimit
|
|
|
|
// ErrContentBlocked indicates the content was blocked by safety filters.
|
|
ErrContentBlocked = errors.New("textgen: content blocked")
|
|
|
|
// ErrTimeout indicates the request timed out.
|
|
ErrTimeout = errors.New("textgen: timeout")
|
|
)
|
|
|
|
// IsRetryableError returns true if the error is transient and worth retrying.
|
|
func IsRetryableError(err error) bool {
|
|
if err == nil {
|
|
return false
|
|
}
|
|
return errors.Is(err, ErrQuotaExceeded) ||
|
|
errors.Is(err, ErrRateLimited) ||
|
|
errors.Is(err, ErrTimeout) ||
|
|
errors.Is(err, routing.ErrServerUnavailable)
|
|
}
|