From: Jeff Halter Date: Sun, 3 Jul 2022 21:56:52 +0000 (-0700) Subject: Add error message handling to client X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/commitdiff_plain/9174dbe8a9057e240fd9c3825c5720d13f2fafc2?ds=inline;hp=-c Add error message handling to client --- 9174dbe8a9057e240fd9c3825c5720d13f2fafc2 diff --git a/hotline/client.go b/hotline/client.go index c322562..83bcfab 100644 --- a/hotline/client.go +++ b/hotline/client.go @@ -237,7 +237,41 @@ func handleTranServerMsg(c *Client, t *Transaction) (res []Transaction, err erro return res, err } +func (c *Client) showErrMsg(msg string) { + time := time.Now().Format(time.RFC850) + + title := "| Error |" + + msgBox := tview.NewTextView().SetScrollable(true) + msgBox.SetText(msg).SetBackgroundColor(tcell.ColorDarkRed) + msgBox.SetTitle(title).SetBorder(true) + msgBox.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { + switch event.Key() { + case tcell.KeyEscape: + c.UI.Pages.RemovePage("serverMsgModal" + time) + } + return event + }) + + centeredFlex := tview.NewFlex(). + AddItem(nil, 0, 1, false). + AddItem(tview.NewFlex().SetDirection(tview.FlexRow). + AddItem(nil, 0, 1, false). + AddItem(msgBox, 0, 2, true). + AddItem(nil, 0, 1, false), 0, 2, true). + AddItem(nil, 0, 1, false) + + c.UI.Pages.AddPage("serverMsgModal"+time, centeredFlex, true, true) + c.UI.App.Draw() // TODO: errModal doesn't render without this. wtf? +} + func handleGetFileNameList(c *Client, t *Transaction) (res []Transaction, err error) { + if t.IsError() { + c.showErrMsg(string(t.GetField(fieldError).Data)) + c.Logger.Infof("Error: %s", t.GetField(fieldError).Data) + return res, err + } + fTree := tview.NewTreeView().SetTopLevel(1) root := tview.NewTreeNode("Root") fTree.SetRoot(root).SetCurrentNode(root) diff --git a/hotline/transaction.go b/hotline/transaction.go index 88e17df..9b0ac40 100644 --- a/hotline/transaction.go +++ b/hotline/transaction.go @@ -1,6 +1,7 @@ package hotline import ( + "bytes" "encoding/binary" "errors" "fmt" @@ -238,3 +239,7 @@ func (t *Transaction) GetField(id int) Field { return Field{} } + +func (t *Transaction) IsError() bool { + return bytes.Compare(t.ErrorCode, []byte{0, 0, 0, 1}) == 0 +}