Skip to content

Commit

Permalink
Added better error handling on time entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Matija Pevec committed Jan 14, 2020
1 parent b30f47d commit 7645df1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions client/timeentry.go
Expand Up @@ -35,12 +35,17 @@ func (c *Client) GetTimeEntries(queryParams string) ([]TimeEntry, error) {
}

var response TimeEntriesResponse
_, err = c.Do(req, &response)
res, err := c.Do(req, &response)
if err != nil {
return nil, err
}

return response.TimeEntries, nil
switch res.StatusCode {
case http.StatusOK:
return response.TimeEntries, nil
default:
return nil, fmt.Errorf("cannot get time entries (status %v)", res.StatusCode)
}
}

type TimeEntryBody struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/status.go
Expand Up @@ -108,7 +108,7 @@ func statusFunc(_ *cobra.Command, _ []string) {
fmt.Printf("[%d] %s %s (%s)\n", u.Id, u.FirstName, u.LastName, u.Email)

t := utils.NewTable()
t.AppendRow(table.Row{"Period", "Hours"})
t.AppendHeader(table.Row{"Period", "Hours"})
t.AppendRow(table.Row{"Today", <-today})
t.AppendRow(table.Row{"Yesterday", <-yesterday})
t.AppendRow(table.Row{"This week", <-thisWeek})
Expand Down

0 comments on commit 7645df1

Please sign in to comment.