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

Capture API exceptions from todoist API

Rather than silently swallow, capture them and use them in rendering
This commit is contained in:
Sean Smith 2019-08-31 18:03:48 -04:00
parent c3a54de181
commit 0f9e07259e
2 changed files with 16 additions and 7 deletions

View File

@ -14,6 +14,10 @@ func (widget *Widget) content() (string, string, bool) {
return widget.CommonSettings().Title, "", false
}
if proj.err != nil {
return widget.CommonSettings().Title, proj.err.Error(), true
}
title := fmt.Sprintf("[green]%s[white]", proj.Project.Name)
str := ""

View File

@ -11,21 +11,22 @@ type Project struct {
index int
tasks []todoist.Task
err error
}
func NewProject(id int) *Project {
// Todoist seems to experience a lot of network issues on their side
// If we can't connect, handle it with an empty project until we can
project, err := todoist.GetProject(id)
if err != nil {
return &Project{}
}
proj := &Project{
Project: project,
index: -1,
}
if err != nil {
proj.err = err
return proj
}
proj.Project = project
proj.loadTasks()
@ -38,7 +39,11 @@ func (proj *Project) isLast() bool {
func (proj *Project) loadTasks() {
tasks, err := todoist.ListTask(todoist.QueryParam{"project_id": fmt.Sprintf("%d", proj.ID)})
if err == nil {
if err != nil {
proj.err = err
proj.tasks = nil
} else {
proj.err = nil
proj.tasks = tasks
}
}