BMW: improve error handling
This commit is contained in:
parent
5ff3b10f34
commit
40fad22f3a
2 changed files with 17 additions and 0 deletions
|
|
@ -10,6 +10,7 @@ import (
|
|||
)
|
||||
|
||||
// https://github.com/bimmerconnected/bimmer_connected
|
||||
// https://github.com/TA2k/ioBroker.bmw
|
||||
|
||||
const ApiURI = "https://b2vapi.bmwgroup.com/webapi/v1"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package bmw
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
|
@ -70,6 +72,20 @@ func (v *Identity) RefreshToken(_ *oauth2.Token) (*oauth2.Token, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode >= http.StatusBadRequest {
|
||||
var desc struct {
|
||||
Error string
|
||||
ErrorDescription string `json:"error_description"`
|
||||
}
|
||||
|
||||
if err := json.NewDecoder(resp.Body).Decode(&desc); err != nil {
|
||||
return nil, fmt.Errorf("could not obtain token")
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s:%s", desc.Error, desc.ErrorDescription)
|
||||
}
|
||||
|
||||
uri := resp.Header.Get("Location")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue