Skip to content

Commit

Permalink
Cohort not modified should not throw exception
Browse files Browse the repository at this point in the history
  • Loading branch information
tyiuhc committed Jul 31, 2024
1 parent c4c4260 commit 73672b2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
4 changes: 2 additions & 2 deletions pkg/experiment/local/cohort_download_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (api *directCohortDownloadApi) getCohort(cohortID string, cohort *Cohort) (
errors++
if errors >= 3 || func(err error) bool {
switch err.(type) {
case *CohortNotModifiedException, *CohortTooLargeException:
case *CohortTooLargeException:
return true
default:
return false
Expand Down Expand Up @@ -85,7 +85,7 @@ func (api *directCohortDownloadApi) getCohort(cohortID string, cohort *Cohort) (
}(),
}, nil
} else if response.StatusCode == http.StatusNoContent {
return nil, &CohortNotModifiedException{Message: "Cohort not modified"}
return nil, nil
} else if response.StatusCode == http.StatusRequestEntityTooLarge {
return nil, &CohortTooLargeException{Message: "Cohort exceeds max cohort size"}
} else {
Expand Down
7 changes: 3 additions & 4 deletions pkg/experiment/local/cohort_download_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,8 @@ func TestCohortDownloadApi(t *testing.T) {
httpmock.NewStringResponder(204, ""),
)

_, err := api.getCohort("1234", cohort)
assert.Error(t, err)
_, isCohortNotModifiedException := err.(*CohortNotModifiedException)
assert.True(t, isCohortNotModifiedException)
result, err := api.getCohort("1234", cohort)
assert.Nil(t, result)
assert.NoError(t, err)
})
}
4 changes: 3 additions & 1 deletion pkg/experiment/local/cohort_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ func (task *CohortLoaderTask) run() {
if err != nil {
task.err = err
} else {
task.loader.cohortStorage.putCohort(cohort)
if cohort != nil {
task.loader.cohortStorage.putCohort(cohort)
}
}

task.loader.removeJob(task.cohortId)
Expand Down
8 changes: 0 additions & 8 deletions pkg/experiment/local/exception.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,3 @@ type CohortTooLargeException struct {
func (e *CohortTooLargeException) Error() string {
return e.Message
}

type CohortNotModifiedException struct {
Message string
}

func (e *CohortNotModifiedException) Error() string {
return e.Message
}

0 comments on commit 73672b2

Please sign in to comment.