Audi: handle odometer errors
This commit is contained in:
parent
b1951dc014
commit
e0f68de753
4 changed files with 13 additions and 2 deletions
|
|
@ -130,9 +130,9 @@ func (d *dumper) Dump(name string, v interface{}) {
|
|||
|
||||
if v, ok := v.(api.VehicleOdometer); ok {
|
||||
if odo, err := v.Odometer(); err != nil {
|
||||
fmt.Fprintf(w, "Odometer:\t%.0f\n", err)
|
||||
fmt.Fprintf(w, "Odometer:\t%v\n", err)
|
||||
} else {
|
||||
fmt.Fprintf(w, "Odometer:\t%vkm\n", odo)
|
||||
fmt.Fprintf(w, "Odometer:\t%.0fkm\n", odo)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ func (r *Helper) GetBody(url string) ([]byte, error) {
|
|||
// decodeJSON reads HTTP response and decodes JSON body if error is nil
|
||||
func decodeJSON(resp *http.Response, res interface{}) error {
|
||||
if err := ResponseError(resp); err != nil {
|
||||
_ = json.NewDecoder(resp.Body).Decode(&res)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,5 +61,9 @@ func (v *API) Status(vin string) (StatusResponse, error) {
|
|||
uri := fmt.Sprintf("%s/bs/vsr/v1/Audi/DE/vehicles/%s/status", DefaultBaseURI, vin)
|
||||
err := v.getJSON(uri, &res)
|
||||
|
||||
if err != nil && res.Error.ErrorCode != "" {
|
||||
err = fmt.Errorf("%w (%s: %s)", err, res.Error.ErrorCode, res.Error.Description)
|
||||
}
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,12 @@ type StatusResponse struct {
|
|||
Data []ServiceDefinition
|
||||
}
|
||||
}
|
||||
Error Error
|
||||
}
|
||||
|
||||
type Error struct {
|
||||
ErrorCode string
|
||||
Description string
|
||||
}
|
||||
|
||||
func (s *StatusResponse) ServiceByID(id string) *ServiceDefinition {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue