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

Merge pull request #587 from Seanstoppable/capturetodoisterrors

Capture API exceptions from todoist API
This commit is contained in:
Chris Cummer 2019-09-01 08:26:50 -07:00 committed by GitHub
commit 0206fd6baf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 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) title := fmt.Sprintf("[green]%s[white]", proj.Project.Name)
str := "" str := ""

View File

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