Volvo: improve error handling
This commit is contained in:
parent
73e8cb4966
commit
f2b6deadb2
2 changed files with 9 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue