mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-15 14:56:42 +00:00
fix: don't logout user if auth refresh fails because internet dropped
This commit is contained in:
@ -21,7 +21,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@ -35,6 +34,7 @@ import (
|
||||
|
||||
pmcrypto "github.com/ProtonMail/gopenpgp/crypto"
|
||||
"github.com/jaytaylor/html2text"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -460,8 +460,10 @@ func (c *client) refreshAccessToken() (err error) {
|
||||
}
|
||||
|
||||
if _, err := c.AuthRefresh(refreshToken); err != nil {
|
||||
c.sendAuth(nil)
|
||||
return err
|
||||
if err != ErrAPINotReachable {
|
||||
c.sendAuth(nil)
|
||||
}
|
||||
return errors.Wrap(err, "failed to refresh auth")
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
@ -293,11 +293,8 @@ func (cm *ClientManager) GetAuthUpdateChannel() chan ClientAuth {
|
||||
return cm.authUpdates
|
||||
}
|
||||
|
||||
// Errors for possible connection issues
|
||||
var (
|
||||
ErrNoInternetConnection = errors.New("no internet connection")
|
||||
ErrCanNotReachAPI = errors.New("can not reach PM API")
|
||||
)
|
||||
// ErrNoInternetConnection indicates that both protonstatus and the API are unreachable.
|
||||
var ErrNoInternetConnection = errors.New("no internet connection")
|
||||
|
||||
// CheckConnection returns an error if there is no internet connection.
|
||||
// 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:
|
||||
cm.log.Error("ProtonStatus is reachable but API is not")
|
||||
return ErrCanNotReachAPI
|
||||
return ErrAPINotReachable
|
||||
|
||||
case errStatus != nil && errAPI == nil:
|
||||
cm.log.Warn("API is reachable but protonstatus is not")
|
||||
|
||||
Reference in New Issue
Block a user