api-structs #117

Merged
lash merged 35 commits from api-structs into master 2024-10-24 15:53:46 +02:00
Showing only changes of commit 08e709f1b3 - Show all commits

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)
Outdated
Review

When is an error response "ok"?

When is an error response "ok"?
Outdated
Review

If unknown, perhaps @kamikazechaser can clear it up

If unknown, perhaps @kamikazechaser can clear it up

In the menu handler's context,we needed a way to decide which error from calling the CreateAccountService we could use to set the flag 'flag_api_call_error' and because an error could occur when calling the CreateAccount that's not associated with an api call,say maybe Unmarshaling,then checking if the Ok field is present and is false is what i considered as an api call failure.

In the menu handler's context,we needed a way to decide which error from calling the CreateAccountService we could use to set the flag 'flag_api_call_error' and because an error could occur when calling the CreateAccount that's not associated with an api call,say maybe Unmarshaling,then checking if the Ok field is present and is false is what i considered as an api call failure.
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 {
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)