Skip to content

Commit

Permalink
Add better error message and automatic retries when registration prov…
Browse files Browse the repository at this point in the history
…ider isn't reachable
  • Loading branch information
tulir committed Jan 9, 2024
1 parent 4d02ea3 commit 335f8fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions imessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func init() {
"im-ids-not-registered": "Missing iMessage registration.",
"im-ids-refresh-credentials": "Credentials expired. Please use the Reconnect button to log in again.",
"im-nacserv-not-configured": "Please enter an iMessage registration code to use the bridge.",
"im-nacserv-fail": "Registration provider couldn't be reached when trying to reregister with iMessage.",
})
}

Expand Down Expand Up @@ -68,6 +69,8 @@ func (user *User) HandleEvent(evt any) {
user.BridgeState.Send(status.BridgeState{StateEvent: status.StateConnected})
case *direct.IDSRegisterFail:
user.BridgeState.Send(status.BridgeState{StateEvent: status.StateUnknownError, Error: "im-ids-register-fail"})
case *direct.NACServFail:
user.BridgeState.Send(status.BridgeState{StateEvent: status.StateBadCredentials, Error: "im-nacserv-fail"})
case *direct.RefreshCredentialsRequired:
user.BridgeState.Send(status.BridgeState{
StateEvent: status.StateBadCredentials,
Expand Down
10 changes: 8 additions & 2 deletions imessage/direct/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ func (dc *Connector) RegisterIDS(ctx context.Context, forceRegister bool) error

if errors.Is(err, types.ErrActionRefreshCredentials) {
err = nil
} else if errors.Is(err, nacserv.ErrProviderNotReachable) {
dc.EventHandler(&NACServFail{err})
dc.nextReregisterCheck = time.Now().Add(1 * time.Hour)
dc.reregisterTicker.Reset(1 * time.Hour)
zerolog.Ctx(ctx).Debug().
Msg("Reset reregister ticker to retry in an hour after nacserv error")
} else if err != nil {
dc.EventHandler(&IDSRegisterFail{err})
} else {
Expand Down Expand Up @@ -829,8 +835,7 @@ func (dc *Connector) handleAPNSMessage(ctx context.Context, payload *apns.SendMe
log.Debug().Msg("Re-fetching own handles due to c:130 from self")
err = dc.RegisterIDS(ctx, false)
if err != nil {
log.Err(err).Msg("Error re-registering IDS")
dc.EventHandler(&IDSRegisterFail{err})
log.Err(err).Msg("Error re-registering IDS after c:130")
}
// TODO broadcast handle to recent entries in IDS cache (without looking up anyone)?
}
Expand Down Expand Up @@ -890,6 +895,7 @@ type RefreshCredentialsRequired struct {
type IDSRegisterFail struct {
Error error
}
type NACServFail IDSRegisterFail
type BridgeInfoUpdated struct{}
type HandlesUpdated struct {
OldHandles []uri.ParsedURI
Expand Down

0 comments on commit 335f8fb

Please sign in to comment.