authorization fix
This commit is contained in:
parent
9e9b0f6083
commit
b1a5e5a5b9
|
@ -16,15 +16,16 @@ type AuthorizationStateHandler interface {
|
|||
func Authorize(client *Client, authorizationStateHandler AuthorizationStateHandler) error {
|
||||
defer authorizationStateHandler.Close()
|
||||
|
||||
var authorizationError error
|
||||
|
||||
for {
|
||||
state, err := client.GetAuthorizationState()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = authorizationStateHandler.Handle(client, state)
|
||||
if err != nil {
|
||||
return err
|
||||
if state.AuthorizationStateType() == TypeAuthorizationStateClosed {
|
||||
return authorizationError
|
||||
}
|
||||
|
||||
if state.AuthorizationStateType() == TypeAuthorizationStateReady {
|
||||
|
@ -32,6 +33,12 @@ func Authorize(client *Client, authorizationStateHandler AuthorizationStateHandl
|
|||
time.Sleep(1 * time.Second)
|
||||
return nil
|
||||
}
|
||||
|
||||
err = authorizationStateHandler.Handle(client, state)
|
||||
if err != nil {
|
||||
authorizationError = err
|
||||
client.Close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,10 +107,10 @@ func (stateHandler *clientAuthorizer) Handle(client *Client, state Authorization
|
|||
return ErrNotSupportedAuthorizationState
|
||||
|
||||
case TypeAuthorizationStateClosing:
|
||||
return ErrNotSupportedAuthorizationState
|
||||
return nil
|
||||
|
||||
case TypeAuthorizationStateClosed:
|
||||
return ErrNotSupportedAuthorizationState
|
||||
return nil
|
||||
}
|
||||
|
||||
return ErrNotSupportedAuthorizationState
|
||||
|
|
|
@ -71,8 +71,6 @@ func NewClient(authorizationStateHandler AuthorizationStateHandler, options ...O
|
|||
|
||||
err := Authorize(client, authorizationStateHandler)
|
||||
if err != nil {
|
||||
client.Stop()
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue