Skip to content

Commit

Permalink
refactor(clockify): wrap errors into client.ErrFetchEntries
Browse files Browse the repository at this point in the history
  • Loading branch information
gabor-boros committed Oct 13, 2021
1 parent 7be81c2 commit 90f3f2b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -37,6 +37,7 @@ All notable changes to this project will be documented in this file.
- Update changelog ([97d9867](https://github.com/gabor-boros/minutes/commit/97d986761306a892d1354228c650615a7146dfba))
- Use commit links in changelog ([8011d6a](https://github.com/gabor-boros/minutes/commit/8011d6af1d1e2ae917da871b16109991e3118812))
- Update changelog entries ([4b6dc29](https://github.com/gabor-boros/minutes/commit/4b6dc2911349587df3207afea4675b1e3e77033f))
- Update changelog ([2fccd28](https://github.com/gabor-boros/minutes/commit/2fccd287eae65a20160141f6091eb12fd1126040))

**Refactor**

Expand All @@ -52,6 +53,7 @@ All notable changes to this project will be documented in this file.
- Do not return pointer slice when splitting ([6a34847](https://github.com/gabor-boros/minutes/commit/6a34847c150815c25c04077daa557ea5855bf3ae))
- Add entry duration splitting as a method ([e657956](https://github.com/gabor-boros/minutes/commit/e657956f78e3fe37be22e3dfbb5dc65a6d345865))
- Use outsourced entry duration splitting ([e81f1fd](https://github.com/gabor-boros/minutes/commit/e81f1fd08b9ffb93c0d74b0d976e0fb915e4fb4d))
- Wrap errors into client.ErrFetchEntries ([5004245](https://github.com/gabor-boros/minutes/commit/5004245d63d9d8e32b4680b51c6edeb908fd162d))

**Testing**

Expand Down
10 changes: 5 additions & 5 deletions internal/pkg/client/clockify/clockify.go
Expand Up @@ -104,7 +104,7 @@ func (c *clockifyClient) getSearchURL(user string, params *WorklogSearchParams)
func (c *clockifyClient) splitEntry(entry worklog.Entry, fetchedEntry FetchEntry) ([]worklog.Entry, error) {
r, err := regexp.Compile(c.opts.TagsAsTasksRegex)
if err != nil {
return nil, err
return nil, fmt.Errorf("%v: %v", client.ErrFetchEntries, err)
}

tasks := map[string]string{}
Expand Down Expand Up @@ -156,17 +156,17 @@ func (c *clockifyClient) FetchEntries(ctx context.Context, opts *client.FetchOpt

searchURL, err := c.getSearchURL(opts.User, searchParams)
if err != nil {
return nil, err
return nil, fmt.Errorf("%v: %v", client.ErrFetchEntries, err)
}

resp, err := client.SendRequest(ctx, http.MethodGet, searchURL, nil, &c.opts.HTTPClientOptions)
if err != nil {
return nil, err
return nil, fmt.Errorf("%v: %v", client.ErrFetchEntries, err)
}

var fetchedEntries []FetchEntry
if err = json.NewDecoder(resp.Body).Decode(&fetchedEntries); err != nil {
return nil, err
return nil, fmt.Errorf("%v: %v", client.ErrFetchEntries, err)
}

// The API returned no entries, meaning no entries left
Expand Down Expand Up @@ -206,7 +206,7 @@ func (c *clockifyClient) FetchEntries(ctx context.Context, opts *client.FetchOpt
if c.opts.TagsAsTasks && len(entry.Tags) > 0 {
pageEntries, err := c.splitEntry(worklogEntry, entry)
if err != nil {
return nil, err
return nil, fmt.Errorf("%v: %v", client.ErrFetchEntries, err)
}

entries = append(entries, pageEntries...)
Expand Down

0 comments on commit 90f3f2b

Please sign in to comment.