worrms icon indicating copy to clipboard operation
worrms copied to clipboard

Ungraceful fail condition on 206 error

Open jebyrnes opened this issue 2 years ago • 2 comments

Hello! Loving this package, as taxize doesn't get synonyms from WORMS that I can tell.

But - I'm running into a funny problem. wm_name2id will often return a 206 error.

library(worrms)

wm_records_name("Asterias rubens")

Error: (206) Partial Content - Asterias rubens

This is odd, as I whipped up a function to do an endrun around the problem, and it works fine

library(dplyr)


get_id <- function(.x){
  
  rec <- try(wm_records_name(.x))
  if(class(rec) == "try-error"){return(NA)}
  
  rec %>%
    filter(status=="accepted") %>%
    pull(AphiaID) 
}

What's going on here? And/or if this is an api, not a package problem, could something like the function I wrote above be a good workaround fail condition?

Here it is without dplyr - and, again, this would only happen if a 206 error was thrown, and I'm guessing a more graceful failure condition (if there are no records) could be added - although if it's a 206, there should be some records.

get_id <- function(.x){
  
  rec <- try(wm_records_name(.x))
  if(class(rec) == "try-error"){return(NA)}
  
  acc <- subset(rec, rec$status=="accepted")
  acc$AphiaID[1]
}

jebyrnes avatar Nov 14 '21 15:11 jebyrnes