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

use entity.MarshalJSON instead of json.Marshal. #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tzzed
Copy link
Contributor

@tzzed tzzed commented May 5, 2022

No description provided.

Verified

This commit was signed with the committer’s verified signature.
targos Michaël Zasso
Copy link
Member

@zarelit zarelit left a comment

Choose a reason for hiding this comment

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

Changes okay, error linting okay, there's one thing to change in the last changed line (see comment)

Comment on lines 816 to 825
if resp.StatusCode == http.StatusCreated {
return resp.Header.Get("Location"), false, nil
} else if resp.StatusCode == http.StatusNoContent {
}

if resp.StatusCode == http.StatusNoContent {
return resp.Header.Get("Location"), true, nil
} else {
bodyBytes, _ := ioutil.ReadAll(resp.Body)
return "", false, fmt.Errorf("Unexpected status code: '%d'\nResponse body: %s", resp.StatusCode, string(bodyBytes))
}
Copy link
Member

Choose a reason for hiding this comment

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

This is not an if statement used to return early because of error, and the most "special" case is the last one. So it's probably better to do one of the following:

  • make this whole block a switch/case statement
  • or remove both the else branches including the one before bodyBytes, _ :=
  • leave the if / else if / else

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.

None yet

2 participants