From 717578eb282f7d326def9eb7e044096dac4122dc Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 24 Oct 2021 11:03:10 +0200 Subject: [PATCH] VW: handle homeregion errors --- vehicle/vw/api.go | 22 +++++----------------- vehicle/vw/types.go | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/vehicle/vw/api.go b/vehicle/vw/api.go index c49eed92b..91d392a50 100644 --- a/vehicle/vw/api.go +++ b/vehicle/vw/api.go @@ -51,29 +51,15 @@ func (v *API) getJSON(uri string, res interface{}) error { return err } -// VehiclesResponse is the /usermanagement/users/v1/%s/%s/vehicles api -type VehiclesResponse struct { - UserVehicles struct { - Vehicle []string - } -} - // Vehicles implements the /vehicles response func (v *API) Vehicles() ([]string, error) { var res VehiclesResponse uri := fmt.Sprintf("%s/usermanagement/users/v1/%s/%s/vehicles", v.baseURI, v.brand, v.country) err := v.getJSON(uri, &res) - return res.UserVehicles.Vehicle, err -} - -// HomeRegion is the home region API response -type HomeRegion struct { - HomeRegion struct { - BaseURI struct { - SystemID string - Content string // api url - } + if err != nil && res.Error != nil { + err = res.Error.Error() } + return res.UserVehicles.Vehicle, err } // HomeRegion updates the home region for the given vehicle @@ -88,6 +74,8 @@ func (v *API) HomeRegion(vin string) error { api = strings.TrimSuffix(api, "/api") + "/fs-car" v.baseURI = api } + } else if res.Error != nil { + err = res.Error.Error() } return err diff --git a/vehicle/vw/types.go b/vehicle/vw/types.go index 6f6e9e99d..9660881ed 100644 --- a/vehicle/vw/types.go +++ b/vehicle/vw/types.go @@ -69,6 +69,25 @@ type ClimaterResponse struct { Error *Error // optional error } +// VehiclesResponse is the /usermanagement/users/v1/%s/%s/vehicles api +type VehiclesResponse struct { + UserVehicles struct { + Vehicle []string + } + Error *Error // optional error +} + +// HomeRegion is the home region API response +type HomeRegion struct { + HomeRegion struct { + BaseURI struct { + SystemID string + Content string // api url + } + } + Error *Error // optional error +} + // TimedInt is an int value with timestamp type TimedInt struct { Content int