fix(chat): show a dialog when the token is rejected

Closes #685
This commit is contained in:
ayn2op 2026-10-12 12:53:27 -04:00
parent 817306b1ad
commit ac05d55da9

View file

@ -9,6 +9,7 @@ import (
"github.com/ayn2op/arikawa/v3/discord" "github.com/ayn2op/arikawa/v3/discord"
"github.com/ayn2op/arikawa/v3/gateway" "github.com/ayn2op/arikawa/v3/gateway"
"github.com/ayn2op/arikawa/v3/utils/ws" "github.com/ayn2op/arikawa/v3/utils/ws"
"github.com/ayn2op/discordo/internal/ui"
"github.com/ayn2op/discordo/internal/ui/chat/composer" "github.com/ayn2op/discordo/internal/ui/chat/composer"
"github.com/ayn2op/discordo/internal/ui/chat/guildstree" "github.com/ayn2op/discordo/internal/ui/chat/guildstree"
"github.com/ayn2op/ningen/v3" "github.com/ayn2op/ningen/v3"
@ -23,10 +24,9 @@ func openState(state *ningen.State) tview.Cmd {
if err := state.Open(context.Background()); err != nil { if err := state.Open(context.Background()); err != nil {
slog.Error("failed to open chat state", "err", err) slog.Error("failed to open chat state", "err", err)
// A rejected token never works again, so ask for a new one. // A rejected token never works again, so say so over the login.
var event *ws.CloseEvent if event, ok := errors.AsType[*ws.CloseEvent](err); ok && event.Code == closeCodeAuthenticationFailed {
if errors.As(err, &event) && event.Code == closeCodeAuthenticationFailed { return tview.Sequence(logout(), func() tview.Msg { return ui.ErrorDialog("open chat state", err) })()
return LogoutMsg{}
} }
} }