Skip to content

Commit

Permalink
connector: humanise connection errors
Browse files Browse the repository at this point in the history
Signed-off-by: Sumner Evans <[email protected]>
  • Loading branch information
sumnerevans committed Nov 26, 2024
1 parent e603aa6 commit 7bda4f7
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"maunium.net/go/mautrix/bridgev2/simplevent"
"maunium.net/go/mautrix/id"

"go.mau.fi/mautrix-telegram/pkg/connector/humanise"
"go.mau.fi/mautrix-telegram/pkg/connector/ids"
"go.mau.fi/mautrix-telegram/pkg/connector/matrixfmt"
"go.mau.fi/mautrix-telegram/pkg/connector/media"
Expand Down Expand Up @@ -399,11 +400,11 @@ func (t *TelegramClient) sendBadCredentials(message string) {
})
}

func (t *TelegramClient) sendUnknownError(message string) {
func (t *TelegramClient) sendUnknownError(err error) {
t.userLogin.BridgeState.Send(status.BridgeState{
StateEvent: status.StateUnknownError,
Error: "tg-not-authenticated",
Message: message,
Error: "tg-unknown-error",
Message: humanise.Error(err),
})
}

Expand All @@ -423,7 +424,7 @@ func (t *TelegramClient) onConnectionStateChange(reason string) func() {

authStatus, err := t.client.Auth().Status(ctx)
if err != nil {
t.sendUnknownError(err.Error())
t.sendUnknownError(err)
} else if authStatus.Authorized {
t.userLogin.BridgeState.Send(status.BridgeState{StateEvent: status.StateConnected})
} else {
Expand Down Expand Up @@ -455,7 +456,7 @@ func (t *TelegramClient) Connect(ctx context.Context) error {
var err error
ctx, t.clientCancel, err = connectTelegramClient(ctx, t.client)
if err != nil {
t.sendUnknownError(err.Error())
t.sendUnknownError(err)
return nil
}
go func() {
Expand All @@ -469,9 +470,9 @@ func (t *TelegramClient) Connect(ctx context.Context) error {
// Update the logged-in user's ghost info (this also updates the user
// login's remote name and profile).
if me, err := t.client.Self(ctx); err != nil {
t.sendUnknownError(fmt.Sprintf("failed to get self: %v", err))
t.sendUnknownError(err)
} else if _, err := t.updateGhost(ctx, t.telegramUserID, me); err != nil {
t.sendUnknownError(fmt.Sprintf("failed to update own ghost: %v", err))
t.sendUnknownError(err)
} else {
t.userLogin.BridgeState.Send(status.BridgeState{StateEvent: status.StateConnected})
}
Expand Down

0 comments on commit 7bda4f7

Please sign in to comment.