Nissan: extract error codes from battery response

This commit is contained in:
andig 2021-09-15 11:39:20 +02:00
parent ccf83bb310
commit 7959b0daec
2 changed files with 13 additions and 2 deletions

View file

@ -100,8 +100,14 @@ func (v *API) Battery() (Response, error) {
err = api.ErrTimeout
}
} else {
// wait for refresh, irrespective of a previous error
err = api.ErrMustRetry
if len(res.Errors) > 0 {
// extract error code
e := res.Errors[0]
err = fmt.Errorf("%s: %s", e.Code, e.Detail)
} else {
// wait for refresh, irrespective of a previous error
err = api.ErrMustRetry
}
}
return res, err

View file

@ -65,6 +65,11 @@ type Response struct {
Type, ID string // battery refresh
Attributes attributes `json:"attributes"`
} `json:"data"`
Errors []Error
}
type Error struct {
Status, Code, Detail string
}
type attributes struct {