Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add request string logging to be able to get more information #155

Merged
merged 7 commits into from
Feb 21, 2024

Conversation

nareshkakubal
Copy link
Collaborator

Add request logging to get more insight when there is a failure

@nareshkakubal nareshkakubal self-assigned this Feb 14, 2024
return nil, fmt.Errorf("invalid ID (%s), expected name:<name of access tier to import>", parts)
}
name := parts[1]
accessTierClient := i.(*client.Holder)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be good to check if the type assertion succeeded?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, sure shall add.

uerr := json.Unmarshal(responseData, &errResp)
if uerr == nil {
myErr := json.Unmarshal(responseData, &errResp)
if myErr == nil {
err = fmt.Errorf("recieved error code %d: %s \n response: \n %s", response.StatusCode, requestStr, responseData)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

misspelling of "received"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this function also return an err here when myErr is non-nil?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i had same thought when i looked into, but looks like idea of the HandleResponse function was to print corresponding errors based on http error code, so when there are parsing errors it is left to the caller to handle. in this above case we need to set err to myErr.

Copy link
Contributor

@yoshiotu yoshiotu Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not returning or handling myErr at all currently.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i saw it, made corresponding change.

@@ -235,8 +244,8 @@ func HandleResponse(response *http.Response, requestStr string) (responseData []
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition is never true

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes so removed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return j.Data, nil
for _, accessTier := range j.Data.AccessTiers {
if accessTier.Name == name {
spec = accessTier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should you add a break statement here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes correct shall add

@nareshkakubal nareshkakubal merged commit 2c21015 into main Feb 21, 2024
1 check passed
@nareshkakubal nareshkakubal deleted the log-request branch February 21, 2024 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants