Volvo: improve error handling

This commit is contained in:
andig 2021-12-03 08:18:10 +01:00
parent 73e8cb4966
commit f2b6deadb2
2 changed files with 9 additions and 0 deletions

View file

@ -92,6 +92,8 @@ func (v *Volvo) vehicles() ([]string, error) {
vehicles = append(vehicles, vehicle.VehicleID)
}
} else if res.ErrorLabel != "" {
err = fmt.Errorf("%w: %s: %s", err, res.ErrorLabel, res.ErrorDescription)
}
return vehicles, err
@ -102,6 +104,9 @@ func (v *Volvo) status() (volvo.Status, error) {
uri := fmt.Sprintf("%s/vehicles/%s/status", volvo.ApiURI, v.vin)
err := v.GetJSON(uri, &res)
if err != nil && res.ErrorLabel != "" {
err = fmt.Errorf("%w: %s: %s", err, res.ErrorLabel, res.ErrorDescription)
}
return res, err
}

View file

@ -8,6 +8,8 @@ import (
const ApiURI = "https://vocapi.wirelesscar.net/customerapi/rest/v3.0"
type AccountResponse struct {
ErrorLabel string `json:"errorLabel"`
ErrorDescription string `json:"errorDescription"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
VehicleRelations []string `json:"accountVehicleRelations"`
@ -25,6 +27,8 @@ type VehicleRelation struct {
}
type Status struct {
ErrorLabel string `json:"errorLabel"`
ErrorDescription string `json:"errorDescription"`
AverageFuelConsumption float32 `json:"averageFuelConsumption"`
AverageFuelConsumptionTimestamp Timestamp `json:"averageFuelConsumptionTimestamp"`
AverageSpeed int `json:"averageSpeed"`