Skip to content

Commit 574080a

Browse files
committed
handlegmessages: don't invalidate credentials on unknown error
1 parent 2310238 commit 574080a

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

pkg/connector/bridgestate.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const (
2626
GMUnpaired status.BridgeStateErrorCode = "gm-unpaired"
2727
GMUnpairedGaia status.BridgeStateErrorCode = "gm-unpaired-gaia"
2828
GMUnpaired404 status.BridgeStateErrorCode = "gm-unpaired-entity-not-found"
29+
GMUnpaired401 status.BridgeStateErrorCode = "gm-unpaired-401-polling"
30+
GMUnpairedInvalidCreds status.BridgeStateErrorCode = "gm-unpaired-invalid-credentials"
2931
GMNotLoggedIn status.BridgeStateErrorCode = "gm-not-logged-in"
3032
GMNotConnected status.BridgeStateErrorCode = "gm-not-connected"
3133
GMConnecting status.BridgeStateErrorCode = "gm-connecting"
@@ -42,10 +44,13 @@ const (
4244
func init() {
4345
status.BridgeStateHumanErrors.Update(status.BridgeStateErrorMap{
4446
GMListenError: "Error polling messages from Google Messages server, the bridge will try to reconnect",
45-
GMFatalError: "Fatal error polling messages from Google Messages server, please re-link the bridge",
47+
GMFatalError: "Fatal error polling messages from Google Messages server",
48+
GMConnectionFailed: "Failed to connect to Google Messages",
4649
GMNotLoggedIn: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS",
4750
GMUnpaired: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS",
4851
GMUnpaired404: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS",
52+
GMUnpaired401: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS",
53+
GMUnpairedInvalidCreds: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS",
4954
GMUnpairedGaia: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS",
5055
GMNotDefaultSMSApp: "Google Messages isn't set as the default SMS app. Please set the default SMS app on your Android phone to Google Messages to continue using SMS/RCS.",
5156
GMBrowserInactive: "Google Messages opened in another browser",

pkg/connector/client.go

+9
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,18 @@ func (gc *GMClient) Connect(ctx context.Context) {
105105
"go_error": err.Error(),
106106
},
107107
})
108+
} else if errors.Is(err, events.ErrInvalidCredentials) {
109+
go gc.invalidateSession(ctx, status.BridgeState{
110+
StateEvent: status.StateBadCredentials,
111+
Error: GMUnpairedInvalidCreds,
112+
Info: map[string]any{
113+
"go_error": err.Error(),
114+
},
115+
})
108116
} else {
109117
gc.UserLogin.BridgeState.Send(status.BridgeState{
110118
StateEvent: status.StateUnknownError,
119+
Error: GMConnectionFailed,
111120
Info: map[string]any{
112121
"go_error": err.Error(),
113122
},

pkg/connector/handlegmessages.go

+21-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,27 @@ func (gc *GMClient) handleGMEvent(rawEvt any) {
4949
ctx := log.WithContext(context.TODO())
5050
switch evt := rawEvt.(type) {
5151
case *events.ListenFatalError:
52-
go gc.invalidateSession(ctx, status.BridgeState{
53-
StateEvent: status.StateUnknownError,
54-
Error: GMFatalError,
55-
Info: map[string]any{"go_error": evt.Error.Error()},
56-
})
52+
if errors.Is(evt.Error, events.ErrInvalidCredentials) {
53+
go gc.invalidateSession(ctx, status.BridgeState{
54+
StateEvent: status.StateBadCredentials,
55+
Error: GMUnpairedInvalidCreds,
56+
Info: map[string]any{"go_error": evt.Error.Error()},
57+
})
58+
} else {
59+
gc.UserLogin.BridgeState.Send(status.BridgeState{
60+
StateEvent: status.StateUnknownError,
61+
Error: GMFatalError,
62+
Info: map[string]any{"go_error": evt.Error.Error()},
63+
})
64+
}
65+
/* TODO determine if this should always invalidate
66+
else if evt.Error.Error() == "http 401 while polling" {
67+
go gc.invalidateSession(ctx, status.BridgeState{
68+
StateEvent: status.StateBadCredentials,
69+
Error: GMUnpaired401,
70+
Info: map[string]any{"go_error": evt.Error.Error()},
71+
})
72+
}*/
5773
case *events.ListenTemporaryError:
5874
gc.longPollingError = evt.Error
5975
gc.UserLogin.BridgeState.Send(status.BridgeState{

pkg/libgm/events/ready.go

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ var ErrRequestedEntityNotFound = RequestError{
3434
},
3535
}
3636

37+
var ErrInvalidCredentials = RequestError{
38+
Data: &gmproto.ErrorResponse{
39+
Type: 16,
40+
Message: "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
41+
},
42+
}
43+
3744
type RequestError struct {
3845
Data *gmproto.ErrorResponse
3946
HTTP *HTTPError

0 commit comments

Comments
 (0)