You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: R/helpers.R
+29-10Lines changed: 29 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -343,29 +343,48 @@ example_ref_ids <- function(visibility = c("public", "internal", "both"), n, see
343
343
}
344
344
}
345
345
346
+
#' Check HTTP response and throw a helpful error if needed
347
+
#'
348
+
#' @param resp HTTP response as returned by `httr2::req_perform()`
349
+
#' @param nice_msg_400 Optional. Custom message for errors in the 400 range
350
+
#' @param nice_msg_500 Optional. Custom message for errors in the 500 range
351
+
#' @param details Optional. Name of JSON field in response body that contains more info about the error
352
+
#' @param call Caller environment
353
+
#'
354
+
#' @keywords internal
355
+
#'
346
356
.validate_resp<-function(resp,
347
357
nice_msg_400,
348
358
nice_msg_500,
359
+
details,
349
360
call=rlang::caller_env()) {
350
361
351
362
if (httr2::resp_is_error(resp)) {
352
-
if (missing(nice_msg_400)) {
353
-
nice_msg_400<- c("i"="There's a problem with your API request. Check reference IDs, search terms, etc. for typos.",
354
-
"i"="If you are an NPS user attempting to edit a reference or access non-public data, verify that you are on the NPS network, have the appropriate permissions, and have set {.arg nps_internal = TRUE} if applicable.",
355
-
"i"="Verify that {.arg dev} is set correctly.")
356
-
}
357
-
if (missing(nice_msg_500)) {
358
-
nice_msg_500<- c("i"="Something seems to have gone wrong on DataStore's end. For troubleshooting help, take a screenshot of this error and contact the package maintainer or the DataStore helpdesk.")
359
-
}
360
363
361
364
status_num<-httr2::resp_status(resp)
362
365
363
-
if (floor(status_num/100) ==5) {
366
+
if (floor(status_num/100) ==5) { # error in 500 range (likely server-side)
367
+
if (missing(nice_msg_500)) {
368
+
nice_msg_500<-"Something seems to have gone wrong on DataStore's end. For troubleshooting help, take a screenshot of this error and contact the package maintainer or the DataStore helpdesk."
369
+
}
364
370
nice_msg<-nice_msg_500
365
-
} elseif (floor(status_num/100) ==4) {
371
+
} elseif (floor(status_num/100) ==4) { # error in 400 range (likely client-side)
372
+
if (missing(nice_msg_400)) {
373
+
nice_msg_400<- c("There's a problem with your API request. Check reference IDs, search terms, etc. for typos.",
374
+
"If you are an NPS user attempting to edit a reference or access non-public data, verify that you are on the NPS network, have the appropriate permissions, and have set {.arg nps_internal = TRUE} if applicable.",
0 commit comments