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 (
"bytes"
"context"
"errors"
"fmt"
"path"
"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 {
flag_account_created, _ := h.flagManager.GetFlag("flag_account_created")
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
okResponse, errResponse := h.accountService.CreateAccount()
if errResponse != nil {
if !errResponse.Ok {
res.FlagSet = append(res.FlagSet, flag_api_call_error)
return nil
}
return errors.New(errResponse.Description)
okResponse, err := h.accountService.CreateAccount()
if err != nil {
return err
}
trackingId := okResponse.Result["trackingId"].(string)
publicKey := okResponse.Result["publicKey"].(string)
res.FlagReset = append(res.FlagReset, flag_api_call_error)
data := map[utils.DataTyp]string{
utils.DATA_TRACKING_ID: trackingId,
utils.DATA_PUBLIC_KEY: publicKey,
}
for key, value := range data {
store := h.userdataStore
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 {
return res, err
}
okResponse, errResponse = h.accountService.TrackAccountStatus(string(publicKey))
if errResponse != nil {
if !errResponse.Ok {
res.FlagSet = append(res.FlagSet, flag_api_error)
}
okResponse, err = h.accountService.TrackAccountStatus(string(publicKey))
if err != nil {
res.FlagSet = append(res.FlagSet, flag_api_error)
return res, err
}
res.FlagReset = append(res.FlagReset, flag_api_error)