forked from urdt/ussd
remove panics after failed execution
This commit is contained in:
parent
560714838f
commit
0c360c0cc4
@ -41,6 +41,7 @@ const (
|
|||||||
Offerings = "OFFERINGS"
|
Offerings = "OFFERINGS"
|
||||||
Recipient = "RECIPIENT"
|
Recipient = "RECIPIENT"
|
||||||
Amount = "AMOUNT"
|
Amount = "AMOUNT"
|
||||||
|
AccountCreated = "ACCOUNTCREATED"
|
||||||
)
|
)
|
||||||
|
|
||||||
func toBytes(s string) []byte {
|
func toBytes(s string) []byte {
|
||||||
@ -146,6 +147,9 @@ func (h *Handlers) CreateAccount(ctx context.Context, sym string, input []byte)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
_, err = h.db.Fetch([]byte(AccountCreated))
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, gdbm.ErrItemNotFound) {
|
||||||
accountResp, err := h.accountService.CreateAccount()
|
accountResp, err := h.accountService.CreateAccount()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.FlagSet = append(res.FlagSet, flags["flag_account_creation_failed"])
|
res.FlagSet = append(res.FlagSet, flags["flag_account_creation_failed"])
|
||||||
@ -161,12 +165,19 @@ func (h *Handlers) CreateAccount(ctx context.Context, sym string, input []byte)
|
|||||||
err := h.db.Store(toBytes(key), toBytes(value), true)
|
err := h.db.Store(toBytes(key), toBytes(value), true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
key := []byte(AccountCreated)
|
||||||
|
value := []byte("1")
|
||||||
|
h.db.Store(key, value, true)
|
||||||
res.FlagSet = append(res.FlagSet, flags["flag_account_created"])
|
res.FlagSet = append(res.FlagSet, flags["flag_account_created"])
|
||||||
return res, err
|
return res, err
|
||||||
|
} else {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SavePin persists the user's PIN choice into the filesystem
|
// SavePin persists the user's PIN choice into the filesystem
|
||||||
@ -609,11 +620,11 @@ func (h *Handlers) TransactionReset(ctx context.Context, sym string, input []byt
|
|||||||
|
|
||||||
err = h.db.Delete([]byte(Amount))
|
err = h.db.Delete([]byte(Amount))
|
||||||
if err != nil && !errors.Is(err, gdbm.ErrItemNotFound) {
|
if err != nil && !errors.Is(err, gdbm.ErrItemNotFound) {
|
||||||
panic(err)
|
return res,err
|
||||||
}
|
}
|
||||||
err = h.db.Delete([]byte(Recipient))
|
err = h.db.Delete([]byte(Recipient))
|
||||||
if err != nil && !errors.Is(err, gdbm.ErrItemNotFound) {
|
if err != nil && !errors.Is(err, gdbm.ErrItemNotFound) {
|
||||||
panic(err)
|
return res,err
|
||||||
}
|
}
|
||||||
|
|
||||||
res.FlagReset = append(res.FlagReset, flags["flag_invalid_recipient"], flags["flag_invalid_recipient_with_invite"])
|
res.FlagReset = append(res.FlagReset, flags["flag_invalid_recipient"], flags["flag_invalid_recipient_with_invite"])
|
||||||
@ -634,7 +645,7 @@ func (h *Handlers) ResetTransactionAmount(ctx context.Context, sym string, input
|
|||||||
|
|
||||||
err = h.db.Delete([]byte(Amount))
|
err = h.db.Delete([]byte(Amount))
|
||||||
if err != nil && !errors.Is(err, gdbm.ErrItemNotFound) {
|
if err != nil && !errors.Is(err, gdbm.ErrItemNotFound) {
|
||||||
panic(err)
|
return res,err
|
||||||
}
|
}
|
||||||
|
|
||||||
res.FlagReset = append(res.FlagReset, flags["flag_invalid_amount"])
|
res.FlagReset = append(res.FlagReset, flags["flag_invalid_amount"])
|
||||||
|
Loading…
Reference in New Issue
Block a user