Skip to content

Commit

Permalink
Fixed error response handling so the program continues if it receives…
Browse files Browse the repository at this point in the history
… an invalid response.
  • Loading branch information
morrisonbrett committed Feb 23, 2016
1 parent bd42ae6 commit 38766e8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
6 changes: 3 additions & 3 deletions TeslaCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func main() {
err = VehicleLib.GetLocation(li.Token, vir.Vehicles[vehicleIndex].ID, &vlr)
if err != nil {
fmt.Println(err)
os.Exit(1)
continue
}

distance := HaversinFormula.Distance(geoFenceLatitude, geoFenceLongitude, vlr.VehicleLocation.Latitude, vlr.VehicleLocation.Longitude)
Expand All @@ -106,7 +106,7 @@ func main() {
err = VehicleLib.GetChargeState(li.Token, vir.Vehicles[vehicleIndex].ID, &vcsr)
if err != nil {
fmt.Println(err)
os.Exit(1)
continue
}

// Check if the vehicle is stopped.
Expand All @@ -121,7 +121,7 @@ func main() {
err = VehicleLib.SendMail(mailServer, mailServerPort, mailServerLogin, mailServerPassword, fromAddress, toAddress, subject, body)
if err != nil {
fmt.Println(err)
os.Exit(1)
continue
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions lib/VehicleLib/VehicleLib.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ func GetChargeState(token string, id int, vcsr *VehicleChargeStateResponse) erro
}

defer resp.Body.Close()
//resp_body, _ := ioutil.ReadAll(resp.Body)

//fmt.Println(resp.Status)
//fmt.Println(string(resp_body))
if resp.StatusCode != 200 {
return fmt.Errorf("GetChargeState response code: %d", resp.StatusCode)
}
Expand Down Expand Up @@ -186,10 +183,7 @@ func GetLocation(token string, id int, vlr *VehicleLocationResponse) error {
}

defer resp.Body.Close()
//resp_body, _ := ioutil.ReadAll(resp.Body)

//fmt.Println(resp.Status)
//fmt.Println(string(resp_body))
if resp.StatusCode != 200 {
return fmt.Errorf("getLocation response code: %d", resp.StatusCode)
}
Expand Down Expand Up @@ -217,7 +211,6 @@ func TeslaLogin(clientid string, clientsecret string, email string, password str

data := url.Values{}
data.Add("grant_type", "password")
//data.Add("token_type", "bearer")
data.Add("client_id", clientid)
data.Add("client_secret", clientsecret)
data.Add("email", email)
Expand Down

0 comments on commit 38766e8

Please sign in to comment.