mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
- go.mod module path + all self-imports: github.com/formancehq/payments -> github.com/hanzo-fi/payments (1590 .go files / 3152 refs; 20 modules: root, pkg/client, pkg/domain, 18 ce/plugins). External dep kept: formancehq/go-libs. - plugins: each ce/plugins/* consumed a *published* pkg/domain; added local 'replace .../pkg/domain => ../../../pkg/domain' (consistent with root) so every standalone plugin module builds in-monorepo. compile-plugin.sh MOD var rebranded too. - branding: README, LICENSE (dual MIT+EE; upstream copyright retained + Hanzo added), goreleaser (release images -> registry.hanzo.ai/hanzo-fi, OCI labels, homepage), proto go_package, renovate, speakeasy gen.yaml, connector-template *.gotpl. - CI: removed Numary/Formance workflows + composite action; added canonical hanzo.yml + cicd.yml (hanzoai/ci, gated HANZO_CI_ENABLED) + secretless ci.yml (go build/vet). - kept as data/compat keys: wire capability enums ALLOW_FORMANCE_*, generated SDK type client.Formance, domain field FormanceRedirectURL, OTEL_SERVICE_NAME, upstream base image. - verified: go build ./... (default + -tags ee) + all 20 nested modules green.
95 lines
3.8 KiB
Go
95 lines
3.8 KiB
Go
package activities
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/hanzo-fi/payments/internal/connectors"
|
|
"github.com/hanzo-fi/payments/internal/connectors/plugins"
|
|
"github.com/hanzo-fi/payments/pkg/domain/models"
|
|
"github.com/hanzo-fi/payments/internal/storage"
|
|
errorsutils "github.com/hanzo-fi/payments/pkg/domain/errors"
|
|
"go.temporal.io/sdk/temporal"
|
|
)
|
|
|
|
const (
|
|
ErrTypeStorage = "STORAGE"
|
|
ErrTypeDefault = "DEFAULT"
|
|
ErrTypeInvalidArgument = "INVALID_ARGUMENT"
|
|
ErrTypeRateLimited = "RATE_LIMITED"
|
|
ErrTypeTimeout = "TIMEOUT"
|
|
ErrTypeRetryAfter = "RETRY_AFTER"
|
|
ErrTypeUnimplemented = "UNIMPLEMENTED"
|
|
)
|
|
|
|
func (a Activities) temporalPluginError(ctx context.Context, err error) error {
|
|
return a.temporalPluginErrorCheck(ctx, err, false)
|
|
}
|
|
|
|
func (a Activities) temporalPluginPollingError(ctx context.Context, err error, periodic bool) error {
|
|
return a.temporalPluginErrorCheck(ctx, err, periodic)
|
|
}
|
|
|
|
func (a Activities) temporalPluginErrorCheck(ctx context.Context, err error, isPeriodic bool) error {
|
|
// Since typed errors are discard with temporal when returning from an activity,
|
|
// we need only to pass to temporal the cause of the error and not all the
|
|
// stack trace.
|
|
cause := errorsutils.Cause(err)
|
|
|
|
switch {
|
|
// Do not retry the following errors
|
|
case errors.Is(err, plugins.ErrNotImplemented):
|
|
return temporal.NewNonRetryableApplicationError(err.Error(), ErrTypeUnimplemented, cause)
|
|
case errors.Is(err, plugins.ErrInvalidClientRequest):
|
|
return temporal.NewNonRetryableApplicationError(err.Error(), ErrTypeInvalidArgument, cause)
|
|
case errors.Is(err, plugins.ErrCurrencyNotSupported):
|
|
return temporal.NewNonRetryableApplicationError(err.Error(), ErrTypeInvalidArgument, cause)
|
|
case errors.Is(err, connectors.ErrNotFound):
|
|
return temporal.NewNonRetryableApplicationError(err.Error(), ErrTypeInvalidArgument, cause)
|
|
case errors.Is(err, models.ErrMissingConnectorMetadata):
|
|
return temporal.NewNonRetryableApplicationError(err.Error(), ErrTypeInvalidArgument, cause)
|
|
case errors.Is(err, models.ErrWebhookVerification):
|
|
return temporal.NewNonRetryableApplicationError(err.Error(), ErrTypeInvalidArgument, cause)
|
|
case errors.As(err, &models.NonRetryableError):
|
|
return temporal.NewNonRetryableApplicationError(err.Error(), ErrTypeInvalidArgument, cause)
|
|
|
|
// Potentially retry
|
|
case errors.Is(err, plugins.ErrUpstreamRatelimit):
|
|
return temporal.NewApplicationErrorWithOptions(err.Error(), ErrTypeRateLimited, temporal.ApplicationErrorOptions{
|
|
// temporal already implements a backoff strategy, but let's add an extra delay before the next retry
|
|
// https://docs.temporal.io/encyclopedia/retry-policies#per-error-next-retry-delay
|
|
NextRetryDelay: a.rateLimitingRetryDelay,
|
|
})
|
|
case errors.Is(err, plugins.ErrUpstreamTimeout):
|
|
return temporal.NewApplicationErrorWithCause(err.Error(), ErrTypeTimeout, cause)
|
|
case errors.Is(err, plugins.ErrUpstreamRetryAfter):
|
|
return temporal.NewApplicationErrorWithOptions(err.Error(), ErrTypeRetryAfter, temporal.ApplicationErrorOptions{
|
|
NextRetryDelay: a.rateLimitingRetryDelay,
|
|
})
|
|
|
|
// Retry the following errors
|
|
case errors.Is(err, plugins.ErrNotYetInstalled):
|
|
// We want to retry in case of not installed
|
|
return temporal.NewApplicationErrorWithCause(err.Error(), ErrTypeDefault, cause)
|
|
default:
|
|
return temporal.NewApplicationErrorWithCause(err.Error(), ErrTypeDefault, cause)
|
|
}
|
|
}
|
|
|
|
func temporalStorageError(err error) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
|
|
switch {
|
|
case errors.Is(err, storage.ErrNotFound),
|
|
errors.Is(err, storage.ErrDuplicateKeyValue),
|
|
errors.Is(err, storage.ErrValidation),
|
|
errors.Is(err, storage.ErrForeignKeyViolation):
|
|
// Do not retry these errors
|
|
return temporal.NewNonRetryableApplicationError(err.Error(), ErrTypeStorage, err)
|
|
default:
|
|
return temporal.NewApplicationErrorWithCause(err.Error(), ErrTypeStorage, err)
|
|
}
|
|
}
|