mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* feat(temporal): return an error when error translating PSP data * add asset check
34 lines
922 B
Go
34 lines
922 B
Go
package engine
|
|
|
|
import (
|
|
"github.com/formancehq/payments/internal/connectors/engine/activities"
|
|
"github.com/formancehq/payments/internal/connectors/engine/workflow"
|
|
errorsutils "github.com/formancehq/payments/internal/utils/errors"
|
|
"github.com/pkg/errors"
|
|
"go.temporal.io/sdk/temporal"
|
|
)
|
|
|
|
var (
|
|
ErrValidation = errors.New("validation error")
|
|
ErrNotFound = errors.New("not found")
|
|
)
|
|
|
|
// handleWorkflowError processes Temporal workflow errors and wraps validation errors
|
|
// with ErrValidation to provide consistent error handling for API responses.
|
|
func handleWorkflowError(err error) error {
|
|
var applicationErr *temporal.ApplicationError
|
|
if errors.As(err, &applicationErr) {
|
|
switch applicationErr.Type() {
|
|
case activities.ErrTypeInvalidArgument, workflow.ErrValidation:
|
|
return errorsutils.NewWrappedError(
|
|
errorsutils.Cause(err),
|
|
ErrValidation,
|
|
)
|
|
default:
|
|
return err
|
|
}
|
|
}
|
|
|
|
return err
|
|
}
|