From 38766e8ba0a62641effb471753da2234146d089f Mon Sep 17 00:00:00 2001 From: Brett Morrison Date: Mon, 22 Feb 2016 22:00:30 -0800 Subject: [PATCH] Fixed error response handling so the program continues if it receives an invalid response. --- TeslaCommand.go | 6 +++--- lib/VehicleLib/VehicleLib.go | 7 ------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/TeslaCommand.go b/TeslaCommand.go index e3353da..8829118 100644 --- a/TeslaCommand.go +++ b/TeslaCommand.go @@ -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) @@ -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. @@ -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 } } } diff --git a/lib/VehicleLib/VehicleLib.go b/lib/VehicleLib/VehicleLib.go index b7b875c..3818d7d 100644 --- a/lib/VehicleLib/VehicleLib.go +++ b/lib/VehicleLib/VehicleLib.go @@ -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) } @@ -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) } @@ -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)