output better error when trying to create already existing cohort
ilevantis opened this issue · 1 comments
ilevantis commented
currently looks like this:
> cb_create_cohort("ilya-r-test1", cb_version="v1")
Error in .cb_create_cohort_v1(cohort_name = cohort_name, cohort_desc = cohort_desc, :
Bad Request (HTTP 400). Failed to create a cohort.
> cb_create_cohort("ilya-r-test2", cb_version="v2")
Error in .cb_create_cohort_v2(cohort_name = cohort_name, cohort_desc = cohort_desc, :
Conflict (HTTP 409). Failed to create a cohort.
ilevantis commented
response does contain more useful information.
find it at res$message
r <- httr::POST(url,
.get_httr_headers(cloudos$token),
query = list("teamId" = cloudos$team_id),
body = list("name" = cohort_name,
"description" = cohort_desc,
"moreFilters" = filters),
encode = "json"
)
if (httr::http_error(r)){
message(httr::content(r)$message)
httr::stop_for_status(r, task = "create a cohort")
}
# parse the content
message("Cohort created successfully.")
res <- httr::content(r)
http_error(x, ...)