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:
@@ -9,13 +9,17 @@ func (widget *Widget) display() {
|
||||
}
|
||||
|
||||
func (widget *Widget) content() (string, string, bool) {
|
||||
title := widget.CommonSettings().Title
|
||||
if widget.err != nil {
|
||||
return title, widget.err.Error(), true
|
||||
}
|
||||
|
||||
project := widget.currentGerritProject()
|
||||
if project == nil {
|
||||
return widget.CommonSettings().Title, "Gerrit project data is unavailable", true
|
||||
return title, "Gerrit project data is unavailable", true
|
||||
}
|
||||
|
||||
title := fmt.Sprintf("%s- %s", widget.CommonSettings().Title, widget.title(project))
|
||||
title = fmt.Sprintf("%s- %s", widget.CommonSettings().Title, widget.title(project))
|
||||
|
||||
_, _, width, _ := widget.View.GetRect()
|
||||
str := widget.settings.common.SigilStr(len(widget.GerritProjects), widget.Idx, width) + "\n"
|
||||
|
||||
@@ -23,6 +23,7 @@ type Widget struct {
|
||||
|
||||
selected int
|
||||
settings *Settings
|
||||
err error
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -76,14 +77,16 @@ func (widget *Widget) Refresh() {
|
||||
}
|
||||
gerrit, err := glb.NewClient(gerritUrl, httpClient)
|
||||
if err != nil {
|
||||
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, err.Error(), true })
|
||||
return
|
||||
}
|
||||
widget.gerrit = gerrit
|
||||
widget.GerritProjects = widget.buildProjectCollection(widget.settings.projects)
|
||||
|
||||
for _, project := range widget.GerritProjects {
|
||||
project.Refresh(widget.settings.username)
|
||||
widget.err = err
|
||||
widget.gerrit = nil
|
||||
widget.GerritProjects = nil
|
||||
} else {
|
||||
widget.err = nil
|
||||
widget.gerrit = gerrit
|
||||
widget.GerritProjects = widget.buildProjectCollection(widget.settings.projects)
|
||||
for _, project := range widget.GerritProjects {
|
||||
project.Refresh(widget.settings.username)
|
||||
}
|
||||
}
|
||||
|
||||
widget.display()
|
||||
|
||||
Reference in New Issue
Block a user