1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Refactor a number of widgets to display client errors

Rather than swallowing or crashing, display appropriate errors
This commit is contained in:
Sean Smith
2019-09-01 13:19:07 -04:00
parent ff77a3deb0
commit 8835f532cc
12 changed files with 83 additions and 60 deletions

View File

@@ -16,6 +16,7 @@ type Widget struct {
stories []Story
settings *Settings
err error
}
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
@@ -43,25 +44,22 @@ func (widget *Widget) Refresh() {
}
storyIds, err := GetStories(widget.settings.storyType)
if storyIds == nil {
return
}
if err != nil {
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, err.Error(), true })
return
}
var stories []Story
for idx := 0; idx < widget.settings.numberOfStories; idx++ {
story, e := GetStory(storyIds[idx])
if e == nil {
stories = append(stories, story)
widget.err = err
widget.stories = nil
widget.SetItemCount(0)
} else {
var stories []Story
for idx := 0; idx < widget.settings.numberOfStories; idx++ {
story, e := GetStory(storyIds[idx])
if e == nil {
stories = append(stories, story)
}
}
widget.stories = stories
widget.SetItemCount(len(stories))
}
widget.stories = stories
widget.SetItemCount(len(stories))
widget.Render()
}
@@ -74,6 +72,11 @@ func (widget *Widget) Render() {
func (widget *Widget) content() (string, string, bool) {
title := fmt.Sprintf("%s - %s stories", widget.CommonSettings().Title, widget.settings.storyType)
if widget.err != nil {
return title, widget.err.Error(), true
}
stories := widget.stories
if stories == nil || len(stories) == 0 {
return title, "No stories to display", false