check for error responses

This commit is contained in:
Carlosokumu 2024-10-24 10:02:15 +03:00
parent 9bc9d04a49
commit 08e709f1b3
Signed by: carlos
GPG Key ID: 7BD6BC8160A5C953

View File

@ -3,7 +3,6 @@ package ussd
import ( import (
"bytes" "bytes"
"context" "context"
"errors"
"fmt" "fmt"
"path" "path"
"regexp" "regexp"
@ -141,24 +140,17 @@ func (h *Handlers) SetLanguage(ctx context.Context, sym string, input []byte) (r
func (h *Handlers) createAccountNoExist(ctx context.Context, sessionId string, res *resource.Result) error { func (h *Handlers) createAccountNoExist(ctx context.Context, sessionId string, res *resource.Result) error {
flag_account_created, _ := h.flagManager.GetFlag("flag_account_created") flag_account_created, _ := h.flagManager.GetFlag("flag_account_created")
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error") okResponse, err := h.accountService.CreateAccount()
okResponse, errResponse := h.accountService.CreateAccount() if err != nil {
if errResponse != nil { return err
if !errResponse.Ok {
res.FlagSet = append(res.FlagSet, flag_api_call_error)
return nil
}
return errors.New(errResponse.Description)
} }
trackingId := okResponse.Result["trackingId"].(string) trackingId := okResponse.Result["trackingId"].(string)
publicKey := okResponse.Result["publicKey"].(string) publicKey := okResponse.Result["publicKey"].(string)
res.FlagReset = append(res.FlagReset, flag_api_call_error)
data := map[utils.DataTyp]string{ data := map[utils.DataTyp]string{
utils.DATA_TRACKING_ID: trackingId, utils.DATA_TRACKING_ID: trackingId,
utils.DATA_PUBLIC_KEY: publicKey, utils.DATA_PUBLIC_KEY: publicKey,
} }
for key, value := range data { for key, value := range data {
store := h.userdataStore store := h.userdataStore
err := store.WriteEntry(ctx, sessionId, key, []byte(value)) err := store.WriteEntry(ctx, sessionId, key, []byte(value))
@ -552,11 +544,9 @@ func (h *Handlers) CheckAccountStatus(ctx context.Context, sym string, input []b
if err != nil { if err != nil {
return res, err return res, err
} }
okResponse, errResponse = h.accountService.TrackAccountStatus(string(publicKey)) okResponse, err = h.accountService.TrackAccountStatus(string(publicKey))
if errResponse != nil { if err != nil {
if !errResponse.Ok { res.FlagSet = append(res.FlagSet, flag_api_error)
res.FlagSet = append(res.FlagSet, flag_api_error)
}
return res, err return res, err
} }
res.FlagReset = append(res.FlagReset, flag_api_error) res.FlagReset = append(res.FlagReset, flag_api_error)