Nissan: extract error codes from battery response
This commit is contained in:
parent
ccf83bb310
commit
7959b0daec
2 changed files with 13 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue