Skip to content

Commit

Permalink
Hoist the body read out of the error branch and don't defer close
Browse files Browse the repository at this point in the history
  • Loading branch information
rys committed Jan 5, 2019
1 parent 931b67b commit 21d59f1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/mbdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ func process() {

response, err := http.PostForm(mbURL, url.Values{"domain": {records[i].Domain}, "password": {records[i].Token}, "command": {command}})

body, _ := ioutil.ReadAll(response.Body)
response.Body.Close()

if err != nil {
log.Println(fmt.Sprintf(mbResponseError, records[i].Host, records[i].Domain, records[i].Record, records[i].TTL, err.Error()))
continue
}

defer response.Body.Close()

if response.StatusCode != 200 {
log.Println(fmt.Sprintf(mbResponseError, records[i].Host, records[i].Domain, records[i].Record, records[i].TTL, response.Status))

body, _ := ioutil.ReadAll(response.Body)
log.Printf("%s", body)

continue
Expand Down

0 comments on commit 21d59f1

Please sign in to comment.