@@ -201,6 +201,27 @@ fhir_batch_to_tibble <- function(result, codings) {
201201 items <- result $ results %|| % list ()
202202 n <- length(codings )
203203
204+ # Collapse a possibly-nested error object to a scalar string. The API
205+ # may return `error` as a plain string, a list like
206+ # `list(code = "concept_not_found", message = "...")`, or something
207+ # else. A list-column here would be expanded into extra tibble rows.
208+ error_to_string <- function (err ) {
209+ if (is.null(err )) return (NA_character_ )
210+ if (is.character(err ) && length(err ) == 1L ) return (err )
211+ if (is.list(err )) {
212+ msg <- err $ message %|| % err $ code %|| % err $ detail
213+ if (! is.null(msg ) && is.character(msg ) && length(msg ) == 1L ) {
214+ return (msg )
215+ }
216+ return (paste(names(err ) %|| % " " , unlist(lapply(err , as.character )),
217+ sep = " =" , collapse = " ; " ))
218+ }
219+ # Zero-length / non-character fallbacks: single-bracket indexing
220+ # returns NA on a length-0 vector instead of throwing. Guards
221+ # against `character(0)`, `integer(0)`, etc.
222+ as.character(err )[1L ]
223+ }
224+
204225 make_row <- function (i ) {
205226 input_coding <- codings [[i ]]
206227 item <- if (i < = length(items )) items [[i ]] else NULL
@@ -221,7 +242,7 @@ fhir_batch_to_tibble <- function(result, codings) {
221242 mapping_type = NA_character_ ,
222243 similarity_score = NA_real_ ,
223244 status = " failed" ,
224- status_detail = item $ error % || % " unresolved "
245+ status_detail = error_to_string( item $ error )
225246 ))
226247 }
227248
0 commit comments