This commit is contained in:
26
docs/snippets/r/api/error_handling.md
Normal file
26
docs/snippets/r/api/error_handling.md
Normal file
@@ -0,0 +1,26 @@
|
||||
```r title="R"
|
||||
library(kreuzberg)
|
||||
|
||||
content <- charToRaw("Hello, world!")
|
||||
|
||||
result <- tryCatch(
|
||||
{
|
||||
json <- extract_bytes_sync(
|
||||
content = content,
|
||||
mime_type = "application/x-nonexistent",
|
||||
config = ExtractionConfig$default()
|
||||
)
|
||||
jsonlite::fromJSON(json, simplifyVector = FALSE)
|
||||
},
|
||||
error = function(e) {
|
||||
message(sprintf("Extraction failed: %s", conditionMessage(e)))
|
||||
NULL
|
||||
}
|
||||
)
|
||||
|
||||
if (is.null(result)) {
|
||||
cat("No content extracted; falling back to original bytes\n")
|
||||
} else {
|
||||
cat(sprintf("Extracted %d characters\n", nchar(result$content)))
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user