From 7bda4f78553c9874e4e28ffb970d4aac59c094f1 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Mon, 25 Nov 2024 17:22:11 -0700 Subject: [PATCH] connector: humanise connection errors Signed-off-by: Sumner Evans --- pkg/connector/client.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/connector/client.go b/pkg/connector/client.go index 535b803f..28301141 100644 --- a/pkg/connector/client.go +++ b/pkg/connector/client.go @@ -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" @@ -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), }) } @@ -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 { @@ -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() { @@ -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}) }