try new errors
All checks were successful
Build and Publish / Metadata (push) Successful in 9s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 1m27s
Build and Publish / BuildAndDeployArm64 (push) Successful in 4m0s

This commit is contained in:
matst80
2025-10-14 15:52:59 +02:00
parent b029a9d05a
commit 9f83717ea9
2 changed files with 34 additions and 7 deletions

View File

@@ -4,24 +4,37 @@ import (
"fmt"
"slices"
"git.tornberg.me/go-cart-actor/pkg/actor"
"git.tornberg.me/go-cart-actor/pkg/messages"
"git.tornberg.me/go-cart-actor/pkg/voucher"
)
func (ctx *MutationContext) AddVoucher(g *CartGrain, m *messages.AddVoucher) error {
if m == nil {
return fmt.Errorf("AddVoucher: nil payload")
return &actor.MutationError{
Message: "AddVoucher: nil payload",
Code: 1001,
StatusCode: 400,
}
}
if slices.ContainsFunc(g.Vouchers, func(v *voucher.Voucher) bool {
return v.Code == m.Code
}) {
return fmt.Errorf("voucher already applied")
return &actor.MutationError{
Message: "voucher already applied",
Code: 1002,
StatusCode: 400,
}
}
voucherData, err := ctx.VoucherService.GetVoucher(m.Code)
if err != nil {
return fmt.Errorf("cant find voucher: %w", err)
return &actor.MutationError{
Message: fmt.Sprintf("cant find voucher: %v", err),
Code: 1003,
StatusCode: 400,
}
}
if voucherData == nil {