File size: 1,536 Bytes
429334c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package charges

import (
	"net/http"

	"github.com/openmeterio/openmeter/pkg/framework/commonhttp"
	"github.com/openmeterio/openmeter/pkg/models"
)

const ErrCodeChargeNamespaceEmpty models.ErrorCode = "charge_namespace_empty"

var ErrChargeNamespaceEmpty = models.NewValidationIssue(
	ErrCodeChargeNamespaceEmpty,
	"namespace must not be empty",
	models.WithFieldString("namespace"),
	models.WithCriticalSeverity(),
	commonhttp.WithHTTPStatusCodeAttribute(http.StatusBadRequest),
)

const ErrCodeChargeNotFound models.ErrorCode = "charge_not_found"

var ErrChargeNotFound = models.NewValidationIssue(
	ErrCodeChargeNotFound,
	"charge not found",
	models.WithFieldString("id"),
	models.WithCriticalSeverity(),
	commonhttp.WithHTTPStatusCodeAttribute(http.StatusNotFound),
)

func NewChargeNotFoundError(namespace, id string) error {
	return ErrChargeNotFound.WithAttr("namespace", namespace).WithAttr("id", id)
}

const ErrCodeChargeInvalid models.ErrorCode = "charge_invalid"

var ErrChargeInvalid = models.NewValidationIssue(
	ErrCodeChargeInvalid,
	"charge is invalid",
	models.WithCriticalSeverity(),
	commonhttp.WithHTTPStatusCodeAttribute(http.StatusBadRequest),
)

const ErrCodeCreditRealizationsAlreadyAllocated models.ErrorCode = "credit_realizations_already_allocated"

var ErrCreditRealizationsAlreadyAllocated = models.NewValidationIssue(
	ErrCodeCreditRealizationsAlreadyAllocated,
	"credit realizations already allocated",
	models.WithCriticalSeverity(),
	commonhttp.WithHTTPStatusCodeAttribute(http.StatusBadRequest),
)