fix: don't logout user if auth refresh fails because internet dropped

This commit is contained in:
James Houlahan
2020-05-25 13:43:45 +02:00
parent 390182d247
commit 7ac4c9aecf
3 changed files with 9 additions and 9 deletions

View File

@ -11,6 +11,7 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/)
### Fixed ### Fixed
* GODT-356 Fix crash when removing account while mail client is fetching messages (regression from GODT-204) * GODT-356 Fix crash when removing account while mail client is fetching messages (regression from GODT-204)
* GODT-390 Don't logout user if AuthRefresh fails because internet was off.
## [v1.2.7] Donghai-hotfix - beta (2020-05-07) ## [v1.2.7] Donghai-hotfix - beta (2020-05-07)

View File

@ -21,7 +21,6 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@ -35,6 +34,7 @@ import (
pmcrypto "github.com/ProtonMail/gopenpgp/crypto" pmcrypto "github.com/ProtonMail/gopenpgp/crypto"
"github.com/jaytaylor/html2text" "github.com/jaytaylor/html2text"
"github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -460,8 +460,10 @@ func (c *client) refreshAccessToken() (err error) {
} }
if _, err := c.AuthRefresh(refreshToken); err != nil { if _, err := c.AuthRefresh(refreshToken); err != nil {
c.sendAuth(nil) if err != ErrAPINotReachable {
return err c.sendAuth(nil)
}
return errors.Wrap(err, "failed to refresh auth")
} }
return return

View File

@ -293,11 +293,8 @@ func (cm *ClientManager) GetAuthUpdateChannel() chan ClientAuth {
return cm.authUpdates return cm.authUpdates
} }
// Errors for possible connection issues // ErrNoInternetConnection indicates that both protonstatus and the API are unreachable.
var ( var ErrNoInternetConnection = errors.New("no internet connection")
ErrNoInternetConnection = errors.New("no internet connection")
ErrCanNotReachAPI = errors.New("can not reach PM API")
)
// CheckConnection returns an error if there is no internet connection. // CheckConnection returns an error if there is no internet connection.
// This should be moved to the ConnectionManager when it is implemented. // This should be moved to the ConnectionManager when it is implemented.
@ -324,7 +321,7 @@ func (cm *ClientManager) CheckConnection() error {
case errStatus == nil && errAPI != nil: case errStatus == nil && errAPI != nil:
cm.log.Error("ProtonStatus is reachable but API is not") cm.log.Error("ProtonStatus is reachable but API is not")
return ErrCanNotReachAPI return ErrAPINotReachable
case errStatus != nil && errAPI == nil: case errStatus != nil && errAPI == nil:
cm.log.Warn("API is reachable but protonstatus is not") cm.log.Warn("API is reachable but protonstatus is not")