api-structs #117

Merged
lash merged 35 commits from api-structs into master 2024-10-24 15:53:46 +02:00
Member

Introduces new api structs that communicate with the local development setup

Introduces new api structs that communicate with the local development setup
carlos added 10 commits 2024-10-18 16:46:01 +02:00
carlos added 6 commits 2024-10-21 10:11:47 +02:00
carlos added 1 commit 2024-10-21 15:54:31 +02:00
carlos added 2 commits 2024-10-22 20:32:10 +02:00
carlos added 2 commits 2024-10-22 20:36:43 +02:00
carlos changed title from WIP: api-structs to api-structs 2024-10-22 20:39:52 +02:00
lash requested changes 2024-10-23 02:15:32 +02:00
@ -11,2 +12,4 @@
"github.com/grassrootseconomics/eth-custodial/pkg/api"
)
type ApiResponse struct {
Owner

why is this needed?

why is this needed?
Author
Member

Well,at the point of making the api call and receiving a response back, we don't really know the response that will be sent back,it can either be an ErrResponse or an OKResponse but we are certain that the ok and description field will be present.So the OK field in the ApiResponse will be used to decide which type to Unmarshal on.

if apiResponse.Ok {
		err = json.Unmarshal([]byte(body), &okResponse)
		if err != nil {
			errResponse.Description = err.Error()
			return nil, &errResponse
		}
		return &okResponse, nil
	} else {
		err := json.Unmarshal([]byte(body), &errResponse)
		if err != nil {
			errResponse.Description = err.Error()
			return nil, &errResponse
		}
		return nil, &errResponse
	}
Well,at the point of making the api call and receiving a response back, we don't really know the response that will be sent back,it can either be an ErrResponse or an OKResponse but we are certain that the ok and description field will be present.So the OK field in the ApiResponse will be used to decide which type to Unmarshal on. ``` if apiResponse.Ok { err = json.Unmarshal([]byte(body), &okResponse) if err != nil { errResponse.Description = err.Error() return nil, &errResponse } return &okResponse, nil } else { err := json.Unmarshal([]byte(body), &errResponse) if err != nil { errResponse.Description = err.Error() return nil, &errResponse } return nil, &errResponse } ```
@ -53,0 +65,4 @@
var okResponse api.OKResponse
var err error
// Construct the URL with the path parameter
url := fmt.Sprintf("%s/%s", config.TrackURL, publicKey)
Owner

I think it is better and safer to use the net/url package for handling urls?

I will add it as a separate issue.

I think it is better and safer to use the `net/url` package for handling urls? I will add it as a separate issue.
Owner
https://git.grassecon.net/urdt/ussd/issues/125
lash marked this conversation as resolved
@ -140,0 +144,4 @@
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
okResponse, errResponse := h.accountService.CreateAccount()
if errResponse != nil {
if !errResponse.Ok {
Owner

When is an error response "ok"?

When is an error response "ok"?
Owner

If unknown, perhaps @kamikazechaser can clear it up

If unknown, perhaps @kamikazechaser can clear it up
Author
Member

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.
carlos added 5 commits 2024-10-24 09:10:30 +02:00
lash requested changes 2024-10-24 14:47:28 +02:00
@ -53,0 +93,4 @@
}
return nil, errors.New(errResponse.Description)
}
if len(okResponse.Result) == EMPTY_RESPONSE {
Owner

I would just use the literal 0 here

I would just use the literal `0` here

If there is no matching tracking id, result.otx will be null.

If there is no matching tracking id, result.otx will be null.
Owner

@kamikazechaser please elaborate is there a missing case?

@kamikazechaser please elaborate is there a missing case?
kamikazechaser reviewed 2024-10-24 14:51:27 +02:00
@ -53,0 +79,4 @@
return nil, err
}
defer resp.Body.Close()

Check the HTTP response code first. If it is >= 400 (Bad request you can then unmarshal to an api.ErrResp.

Check the HTTP response code first. If it is >= 400 (Bad request you can then unmarshal to an api.ErrResp.
lash added 1 commit 2024-10-24 15:19:08 +02:00
carlos added 5 commits 2024-10-24 15:37:33 +02:00
carlos added 1 commit 2024-10-24 15:41:49 +02:00
carlos added 1 commit 2024-10-24 15:45:32 +02:00
delete cover.out
carlos added 1 commit 2024-10-24 15:45:53 +02:00
delete cover.html
lash merged commit 453fea569a into master 2024-10-24 15:53:46 +02:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: urdt/ussd#117
No description provided.