PSA: fix misleading login error (#1059)
This commit is contained in:
parent
b010f14b71
commit
70da155c3d
1 changed files with 13 additions and 11 deletions
|
|
@ -2,6 +2,7 @@ package vehicle
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
|
@ -67,21 +68,22 @@ func newPSA(log *util.Logger, brand, realm string, other map[string]interface{})
|
|||
|
||||
api := psa.NewAPI(log, brand, realm, cc.ClientID, cc.ClientSecret)
|
||||
err := api.Login(cc.User, cc.Password)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("login failed: %w", err)
|
||||
}
|
||||
|
||||
var vehicles []psa.Vehicle
|
||||
if err == nil {
|
||||
vehicles, err = api.Vehicles()
|
||||
vehicles, err := api.Vehicles()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var vid string
|
||||
if err == nil {
|
||||
if cc.VIN == "" && len(vehicles) == 1 {
|
||||
vid = vehicles[0].ID
|
||||
} else {
|
||||
for _, vehicle := range vehicles {
|
||||
if vehicle.VIN == strings.ToUpper(cc.VIN) {
|
||||
vid = vehicle.ID
|
||||
}
|
||||
if cc.VIN == "" && len(vehicles) == 1 {
|
||||
vid = vehicles[0].ID
|
||||
} else {
|
||||
for _, vehicle := range vehicles {
|
||||
if vehicle.VIN == strings.ToUpper(cc.VIN) {
|
||||
vid = vehicle.ID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue