Skip to content

Commit 4f0c15f

Browse files
committed
bridgestate: rename some error codes
1 parent 92f1610 commit 4f0c15f

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

pkg/connector/bridgestate.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ const (
2424
GMListenError status.BridgeStateErrorCode = "gm-listen-error"
2525
GMFatalError status.BridgeStateErrorCode = "gm-listen-fatal-error"
2626
GMUnpaired status.BridgeStateErrorCode = "gm-unpaired"
27-
GMUnpairedGaia status.BridgeStateErrorCode = "gm-unpaired-gaia"
2827
GMUnpaired404 status.BridgeStateErrorCode = "gm-unpaired-entity-not-found"
29-
GMUnpaired401 status.BridgeStateErrorCode = "gm-unpaired-401-polling"
30-
GMUnpairedInvalidCreds status.BridgeStateErrorCode = "gm-unpaired-invalid-credentials"
31-
GMUnpairedNoEmailInConfig status.BridgeStateErrorCode = "gm-unpaired-no-email-in-config"
28+
GMLoggedOut401 status.BridgeStateErrorCode = "gm-logged-out-401-polling"
29+
GMLoggedOutInvalidCreds status.BridgeStateErrorCode = "gm-logged-out-invalid-credentials"
30+
GMLoggedOutNoEmailInConfig status.BridgeStateErrorCode = "gm-logged-out-no-email-in-config"
3231
GMNotLoggedIn status.BridgeStateErrorCode = "gm-not-logged-in"
33-
GMNotConnected status.BridgeStateErrorCode = "gm-not-connected"
32+
GMNotLoggedInCanReauth status.BridgeStateErrorCode = "gm-not-logged-in-can-reauth"
3433
GMConnecting status.BridgeStateErrorCode = "gm-connecting"
3534
GMConnectionFailed status.BridgeStateErrorCode = "gm-connection-failed"
3635
GMConfigFetchFailed status.BridgeStateErrorCode = "gm-config-fetch-failed"
@@ -47,14 +46,14 @@ func init() {
4746
status.BridgeStateHumanErrors.Update(status.BridgeStateErrorMap{
4847
GMListenError: "Error polling messages from Google Messages server, the bridge will try to reconnect",
4948
GMFatalError: "Fatal error polling messages from Google Messages server",
50-
GMConnectionFailed: "Failed to connect to Google Messages",
49+
GMConfigFetchFailed: "Failed to initialize connection to Google Messages",
5150
GMNotLoggedIn: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS",
51+
GMNotLoggedInCanReauth: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS",
5252
GMUnpaired: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS",
5353
GMUnpaired404: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS",
54-
GMUnpaired401: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS",
55-
GMUnpairedInvalidCreds: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS",
56-
GMUnpairedNoEmailInConfig: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS",
57-
GMUnpairedGaia: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS",
54+
GMLoggedOut401: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS",
55+
GMLoggedOutInvalidCreds: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS",
56+
GMLoggedOutNoEmailInConfig: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS",
5857
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.",
5958
GMBrowserInactive: "Google Messages opened in another browser",
6059
GMBrowserInactiveTimeout: "Google Messages disconnected due to timeout",

pkg/connector/client.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,18 @@ func (gc *GMConnector) LoadUserLogin(ctx context.Context, login *bridgev2.UserLo
8989
}
9090

9191
func (gc *GMClient) Connect(ctx context.Context) {
92-
if gc.Client == nil || (gc.Meta.Session.AuthNetwork() == util.GoogleNetwork && !gc.Meta.Session.HasCookies()) {
92+
if gc.Client == nil {
9393
gc.UserLogin.BridgeState.Send(status.BridgeState{
9494
StateEvent: status.StateBadCredentials,
9595
Error: GMNotLoggedIn,
9696
})
9797
return
98+
} else if gc.Meta.Session.AuthNetwork() == util.GoogleNetwork && !gc.Meta.Session.HasCookies() {
99+
gc.UserLogin.BridgeState.Send(status.BridgeState{
100+
StateEvent: status.StateBadCredentials,
101+
Error: GMNotLoggedInCanReauth,
102+
})
103+
return
98104
}
99105
err := gc.Client.FetchConfig(ctx)
100106
if err != nil {
@@ -111,7 +117,7 @@ func (gc *GMClient) Connect(ctx context.Context) {
111117
zerolog.Ctx(ctx).Error().Msg("No email in config, invalidating session")
112118
go gc.invalidateSession(ctx, status.BridgeState{
113119
StateEvent: status.StateBadCredentials,
114-
Error: GMUnpairedInvalidCreds,
120+
Error: GMLoggedOutNoEmailInConfig,
115121
}, false)
116122
return
117123
}
@@ -125,10 +131,10 @@ func (gc *GMClient) Connect(ctx context.Context) {
125131
"go_error": err.Error(),
126132
},
127133
}, true)
128-
} else if errors.Is(err, events.ErrInvalidCredentials) || err.Error() == "http 401 while polling" {
134+
} else if errors.Is(err, events.ErrInvalidCredentials) {
129135
go gc.invalidateSession(ctx, status.BridgeState{
130136
StateEvent: status.StateBadCredentials,
131-
Error: GMUnpairedInvalidCreds,
137+
Error: GMLoggedOutInvalidCreds,
132138
Info: map[string]any{
133139
"go_error": err.Error(),
134140
},

pkg/connector/handlegmessages.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ func (gc *GMClient) handleGMEvent(rawEvt any) {
5050
switch evt := rawEvt.(type) {
5151
case *events.ListenFatalError:
5252
if errors.Is(evt.Error, events.ErrInvalidCredentials) || evt.Error.Error() == "http 401 while polling" {
53+
errCode := GMLoggedOut401
54+
if errors.Is(evt.Error, events.ErrInvalidCredentials) {
55+
errCode = GMLoggedOutInvalidCreds
56+
}
5357
go gc.invalidateSession(ctx, status.BridgeState{
5458
StateEvent: status.StateBadCredentials,
55-
Error: GMUnpairedInvalidCreds,
59+
Error: errCode,
5660
Info: map[string]any{"go_error": evt.Error.Error()},
5761
}, false)
5862
} else {
@@ -62,14 +66,6 @@ func (gc *GMClient) handleGMEvent(rawEvt any) {
6266
Info: map[string]any{"go_error": evt.Error.Error()},
6367
})
6468
}
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-
}, false)
72-
}*/
7369
case *events.ListenTemporaryError:
7470
gc.longPollingError = evt.Error
7571
gc.UserLogin.BridgeState.Send(status.BridgeState{

0 commit comments

Comments
 (0)