File size: 515 Bytes
16cdcb7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package subscriptionworkflow

import (
	"github.com/samber/lo"

	"github.com/openmeterio/openmeter/openmeter/subscription"
	"github.com/openmeterio/openmeter/pkg/models"
)

func MapSubscriptionErrors(err error) error {
	if err == nil {
		return nil
	}

	if sErr, ok := lo.ErrorsAs[*subscription.SpecValidationError](err); ok {
		return models.NewGenericValidationError(sErr)
	} else if sErr, ok := lo.ErrorsAs[*subscription.AlignmentError](err); ok {
		return models.NewGenericConflictError(sErr)
	}

	return err
}