|
41 | 41 | connection_timeout <- 30L |
42 | 42 |
|
43 | 43 | # Step 1 – Initiate (empty POST; explicit empty body for compatibility) |
44 | | - init_resp <- .make_req(api_url, paste0(file_kind, "/initiate"), auth_token) |> |
45 | | - req_method("POST") |> |
46 | | - httr2::req_body_raw(raw(0), type = "application/json") |> |
47 | | - req_timeout(connection_timeout) |> |
48 | | - req_perform() |> |
49 | | - resp_body_json() |
| 44 | + init_resp <- tryCatch( |
| 45 | + .make_req(api_url, paste0(file_kind, "/initiate"), auth_token) |> |
| 46 | + req_method("POST") |> |
| 47 | + httr2::req_body_raw(raw(0), type = "application/json") |> |
| 48 | + req_timeout(connection_timeout) |> |
| 49 | + req_perform() |> |
| 50 | + resp_body_json(), |
| 51 | + error = function(e) { .stop_if_rate_limited(e); stop(e) } |
| 52 | + ) |
50 | 53 |
|
51 | 54 | upload_id <- init_resp$upload_id |
52 | 55 | chunk_size <- as.integer(init_resp$chunk_size_bytes %||% (5L * 1024L * 1024L)) |
|
86 | 89 | req_perform() |
87 | 90 | list(ok = TRUE) |
88 | 91 | }, error = function(e) { |
| 92 | + .stop_if_rate_limited(e) |
89 | 93 | list(ok = FALSE, chunk_idx = chunk_idx, message = conditionMessage(e)) |
90 | 94 | }) |
91 | 95 | } |
|
102 | 106 | } |
103 | 107 | } |
104 | 108 | # Step 3 – Complete (empty POST; explicit empty body for compatibility) |
105 | | - complete_resp <- .make_req(api_url, paste0(upload_id, "/complete"), auth_token) |> |
106 | | - req_method("POST") |> |
107 | | - httr2::req_body_raw(raw(0), type = "application/json") |> |
108 | | - req_timeout(connection_timeout) |> |
109 | | - req_perform() |> |
110 | | - resp_body_json() |
| 109 | + complete_resp <- tryCatch( |
| 110 | + .make_req(api_url, paste0(upload_id, "/complete"), auth_token) |> |
| 111 | + req_method("POST") |> |
| 112 | + httr2::req_body_raw(raw(0), type = "application/json") |> |
| 113 | + req_timeout(connection_timeout) |> |
| 114 | + req_perform() |> |
| 115 | + resp_body_json(), |
| 116 | + error = function(e) { .stop_if_rate_limited(e); stop(e) } |
| 117 | + ) |
111 | 118 |
|
112 | 119 | complete_resp |
113 | 120 | } |
|
167 | 174 | return(as.character(job_id)) |
168 | 175 |
|
169 | 176 | }, error = function(e) { |
170 | | - # Log the error |
| 177 | + .stop_if_rate_limited(e) |
171 | 178 | cat("An error occurred:", conditionMessage(e), "\n") |
172 | | - |
173 | | - # Return NA for any error |
174 | 179 | return(NA_character_) |
175 | 180 | }) |
176 | 181 | } |
|
0 commit comments